此代码正常工作,直到我尝试添加"响应"用户必须输入#" p"生成一个随机数6次。我无法识别#variable"响应"和" yournum"从第一个if语句开始。
就像我说它只适用于" yournum"变量 - 我只想要
用户点击" P"所以它一次生成一行。
import random
count = 0
response = 0
yournum = 0
print("Hello! Welcome to the Lottery Picker \n ")
print("Hit the letter P to pick each line or any other letter to quit ")
response = input()
while count < 6:
#response = 0
if yournum == 0 and response == "P":
number = random.randint(1, 49)
print("Your first number is: " + str(number))
count = count + 1
yournum = yournum + 1
elif yournum == 1 and response == "p":
number = random.randint(1, 49)
print("Your second number is: " + str(number))
count = count + 1
yournum = yournum + 1
print("Hit the letter P to another number ")
#response = 0
response = input()
elif yournum == 2 and response == "p":
number = random.randint(1, 49)
print("Your third number is: " + str(number))
count = count + 1
yournum = yournum + 1
print("Hit the letter P to another number ")
#response = 0
response = input()
elif yournum == 3 and response == "p":
number = random.randint(1, 49)
print("Your fourth number is: " + str(number))
count = count + 1
yournum = yournum + 1
print("Hit the letter P to another number ")
#response = 0
response = input()
elif yournum == 4 and response == "p":
number = random.randint(1, 49)
print("Your fifth number is: " + str(number))
count = count + 1
yournum = yournum + 1
print("Hit the letter P to another number ")
#response = 0
response = input()
elif yournum == 5 and response == "p":
number = random.randint(1, 49)
print("And your powerball number is: " + str(number))
count = count + 1
print("Hit the letter P to another number ")
#response = 0
response = input()
else:
count = count + 1
print("Something is wrong with the lottery picker - goodbye ")
答案 0 :(得分:1)
您错过了用户输入“P”的请求以及第一个if行中的latin1
行。此外,您的后续if语句检查针对小写“p”的响应,而不是像第一个那样检查大写“P”。假设大写“P”是正确的,您更新的代码是:
response = input()