基础
Code-GFX
这个作者很懒,什么都没留下…
展开
-
Java练习:删除字符串中所有的元音字母包含大小写
题目:您的任务是编写一个函数,该函数接受一个字符串并返回一个删除了所有元音的新字符串。例如: “This website is for losers LOL!” => “Ths wbst s fr lsrs LL!”public class DisemvowelTrolls {// public static String disemvowel(String string) {// String[] strings = {"a","e","i","o","u","A","E原创 2021-03-27 19:01:04 · 544 阅读 · 0 评论 -
Java练习:反转字符串
题目:编写一个函数,该函数接受一个或多个单词的字符串,并返回相同的字符串,但所有五个或多个字母单词都反转了。传入的字符串将仅包含字母和空格。仅当存在多个单词时才包含空格例如:spinWords( “Hey fellow warriors” ) => returns “Hey wollef sroirraw”spinWords( “This is a test”) => returns “This is a test”spinWords( “This is another test” )=原创 2021-03-27 18:25:46 · 631 阅读 · 0 评论 -
Python的for语句
for语句通常用来执行循环,当循环条件成立,进入循环体for else 语句当for语句正常执行完之后会执行else的语句,for 中执行了break语句则不会执行else中的语句了# for elsefor i in range(10): print(i)else: print('输出完成')for i in range(10): print(i) if i == 4: breakelse: print('输出完成')for i原创 2021-03-08 14:38:09 · 105 阅读 · 0 评论 -
Python中的while语句
while语句通常用来执行循环,当循环条件成立,进入循环体while else 语句当while 语句正常执行完之后会执行else的语句,while 中执行了break语句则不会执行else中的语句了i = 1while i < 10: print(i) i += 1else: print('正常执行完成') i = 1while i < 10: print(i) i += 1 if i == 4: b原创 2021-03-08 14:33:17 · 77 阅读 · 0 评论 -
Python输出九九乘法表
for i in range(1,10): for j in range(1,i+1): print(f'{j} * {i} = {i * j}',end='\t') print('\n')i = 1j = 1while i < 10: while j < i +1: print(f'{j} * {i} = {j * i}',end='\t') j += 1 print('\n') j = 1原创 2021-03-08 14:25:26 · 5448 阅读 · 2 评论 -
Python的三目运算符
# 三目运算符# 格式: 条件成立的表达式 if 条件 else 条件不成立的表达式num1 = 10num2 = 20num3 = num1 if num1 > num2 else num2print(num3)原创 2021-03-08 14:09:04 · 74 阅读 · 0 评论 -
python简单的猜拳游戏
使用if语句实现一个简单的猜拳游戏import randomprint('0-石头,1-剪刀,2-布')computer_guess = random.randint(0,2)while True: gamer_guess = int(input('请输入您要猜的拳')) if gamer_guess < 0 or gamer_guess > 2: print('请重新输入') else: breakif ((gamer_gues原创 2021-03-08 11:53:12 · 312 阅读 · 0 评论 -
Python的if语句
Python的if语句简单理解就是if的语句是一种流程的语句,满足条件进行一种操作,不满足条件进行另一种操作age = int(input('请输入你的年龄:'))if age >= 18: print(f'你的年龄是{age},成年人')else: print('你的年龄是{age},快快长大')多分支的if-else语句age = int(input('请输入你的年龄:'))if age < 18: print(f'你的年龄是{age},童工')el原创 2021-03-08 11:34:57 · 194 阅读 · 0 评论 -
Python接受数据及简单数据类型转换
Python接受数据及数据类型转换Python中通过input接受数据,接受的数据全为str类型,当接受的数据需要进行一定操作时,有可能因为类型的原因而报错,则需要将接受的数据转换为特定的数据类型password = input("请输入您的密码:")print(f'你输入的密码是{password}')print(type(password))Python的数据类型转换数据类型(数据)eval()num = 1num1 = 1.1str1 = '1.1'str2 = '(10,原创 2021-03-08 11:19:12 · 395 阅读 · 0 评论 -
Python3的print结束符
Python3的print结束符Python3中的print输出后默认会换行,其代码print('hello world')#真实的形式print('hello world', end='\n')输出的示例print('hello', end='\n')print('world', end='\t')print('hello')print('world', end='...')print('hello')...原创 2021-03-08 10:57:07 · 975 阅读 · 0 评论 -
Python的格式化输出
Python的格式化输出拼接字符串输出% 格式化输出f ‘{}’ 格式化字符串name = 'chris'age = 21weight = 84.5stu_id = 1# 输出:我的名字是xprint('我的名字是' + name)print('我的名字是%s' % name)# 输出: chris的详细信息print('我的名字是%s,我的年龄是%d,我的体重是%f,我的学号是%d' % (name, age, weight, stu_id))print('我的名原创 2021-03-08 10:50:25 · 90 阅读 · 0 评论 -
Python的数据类型
python是一种面向对象的解释型语言Python的数据类型整型浮点型布尔型字符串元组列表集合字符串python中不需要指定数据类型,在程序运行时将被赋予特定的数据类型原创 2021-03-08 10:23:28 · 117 阅读 · 0 评论