import random num = random.randint(1, 10)running = True while running:answer = int(inpu...
import random num = random.randint(1, 10)running = True while running:answer = int(inpu...
import random all_choices = ['石头', '剪刀', '布']win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布...
import random all_choices = ['石头', '剪刀', '布']computer = random.choice(all_choices)playe...
score = int(input('分数: ')) if score >= 60 and score < 70:print('及格')elif 70 <= score < ...
score = int(input('分数: ')) if score >= 90:print('优秀')elif score >= 80:print('好')elif sc...
import random num = random.randint(1, 10) # 随机生成1-10之间的数字answer = int(input('guess a nu...
import getpass # 导入模块 username = input('username: ') getpass模块中,有一个方法也叫getpass passwor...
a = 10b = 20 if a < b:smaller = aelse:smaller = b print(smaller) s = a if a < b else b ...
单个的数据也可作为判断条件。任何值为0的数字、空对象都是False,任何非0数字、非空对象都是True。if 3 > 0:print('yes')print('ok') if...
字典是key-value(键-值)对形式的,没有顺序,通过键取出值 adict = {'name': 'bob', 'age': 23}len(adict)'bob' in ...
元组与列表基本上是一样的,只是元组不可变,列表可变atuple = (10, 20, 30, 'bob', 'alice', [1,2,3])len(atuple)10 in...
列表也是序列对象,但它是容器类型,列表中可以包含各种数据alist = [10, 20, 30, 'bob', 'alice', [1,2,3]]len(alist)alis...
python中,单双引号没有区别,表示一样的含义sentence = 'tom's pet is a cat' # 单引号中间还有单引号,可以转义sentence2 = "...
username = input('username: ')print('welcome', username) # print各项间默认以空格作为分隔符print('w...
number = input("请输入数字: ") # input用于获取键盘输入print(number)print(type(number)) # input获得的数...
运算符可以分为:算术运算符、比较运算符和逻辑运算符。优先级是:算术运算符>比较运算符>逻辑运算符。不过呢,开始没背下来优先级,最好使用括号。这样不用背,也增加了代码的可读性。...
print('hello world!')print('hello', 'world!') # 逗号自动添加默认的分隔符:空格print('hello' + 'world!...