因为循环次数是已知的,实际使用时,建议用for循环 sum100 = 0 counter = 1 while counter < 101: sum100 += counter counter += 1 print(sum100)
import random num = random.randint(1, 10) counter = 0 while counter < 5: answer = int(input('guess the number: ')) if answer > num: print('猜大了') elif answer < num: pr…
import random num = random.randint(1, 10) running = True while running: answer = int(input('guess the number: ')) if answer > num: print('猜大了') elif answer < num: print(…
import random all_choices = ['石头', '剪刀', '布'] win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']] prompt = """(0) 石头 (1) 剪刀 (2) 布 请选择(0/1/2): """ computer = random.choice(all_…
import random all_choices = ['石头', '剪刀', '布'] computer = random.choice(all_choices) player = input('请出拳: ') # print('Your choice:', player, "Computer's choice:", computer) pri…
score = int(input('分数: ')) if score >= 60 and score < 70: print('及格') elif 70 <= score < 80: print('良') elif 80 <= score < 90: print('好') elif score >= 90…
score = int(input('分数: ')) if score >= 90: print('优秀') elif score >= 80: print('好') elif score >= 70: print('良') elif score >= 60: print('及格') else: print('你要努力了')
import random num = random.randint(1, 10) # 随机生成1-10之间的数字 answer = int(input('guess a number: ')) # 将用户输入的字符转成整数 if answer > num: print('猜大了') elif answer < num: print('…
import getpass # 导入模块 username = input('username: ') # getpass模块中,有一个方法也叫getpass password = getpass.getpass('password: ') if username == 'bob' and password == '123456': print(…
a = 10 b = 20 if a < b: smaller = a else: smaller = b print(smaller) s = a if a < b else b # 和上面的if-else语句等价 print(s)