这段代码运行良好,直到我尝试添加“response”,用户必须输入#“p”才能生成一个随机数6次。我无法从第一个if语句中识别变量“response”和“yournum”。你知道吗
就像我说的,只需使用“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 ")
在第一个if案例中,您缺少用户输入“p”和
response = input()
行的请求。另外,后面的if语句将根据小写“p”而不是像第一个一样的大写“p”检查响应。假设大写字母“P”是正确的,则更新的代码为:相关问题 更多 >
编程相关推荐