| 
 | 
 
 
发表于 2022-9-10 14:50:01
|
显示全部楼层
 
 
 
 本帖最后由 hveagle 于 2022-9-10 14:56 编辑  
 
1 Your Demo 你的代码 
- import random
 
 - no = random.randint(1,4)
 
 - name = input("请输入您的姓名:")
 
 - print('你好,' + name + '!''开始答题')
 
 - temp = input("1+1:")
 
 - guess = int(temp)
 
 - while guess != 2:
 
 -     if guess < 2:
 
 -             print('小了')
 
 -     if guess > 2:
 
 -             print("大了")
 
 -     temp = input("新的填入:")
 
 -     guess = int(temp)
 
 - print("通知:正确")
 
  
- temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
 
 - yet = int(temp)
 
 - if yet != no:
 
 -     print('错了!答案:' + no + '!')
 
 - else:
 
 -     print('对了!答案:'+ no + '!')
 
 - print()
 
  复制代码 
2 My Demo 我的代码 
- import random
 
 - no = random.randint(1,4)
 
 - name = input("请输入您的姓名:")
 
 - print('你好,' + name + '!''开始答题')
 
 - temp = input("1+1:")
 
 - guess = int(temp)
 
 - while guess != 2:
 
 -     if guess < 2:
 
 -             print('小了')
 
 -     if guess > 2:
 
 -             print("大了")
 
 -     temp = input("新的填入:")
 
 -     guess = int(temp)
 
 - print("通知:正确")
 
  
- temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:")
 
 - yet = int(temp)
 
 - if yet != no:
 
 -     print('错了!答案:' + str(no) + '!')
 
 - else:
 
 -     print('对了!答案:'+ str(no) + '!')
 
 - print()
 
  复制代码 
3 Demo difference 代码差别(由于要批注,所以不用代码样式,红色代表要补上的部分,绿色代表要删掉的部分) 
import random 
no = random.randint(1,4) 
name = input("请输入您的姓名:") 
print('你好,' + name + '!''开始答题') 
temp = input("1+1:") 
guess = int(temp) 
while guess != 2: 
    if guess < 2: 
            print('小了') 
    if guess > 2: 
            print("大了") 
    temp = input("新的填入:") 
    guess = int(temp) 
print("通知:正确") 
 
temp = input("有时候运气也是实力的一种,猜1~4的数《模拟考题不会》:") 
yet = int(temp) 
if yet != no: 
    print('错了!答案:' + str(no) + '!') 
else: 
    print('对了!答案:'+ str(no) + '!') 
print() |   
 
 
 
 |