Python 选择后重新启动代码不在';选择';变量
所以,我正试图为我的祖父母制作一个惊喜节目,产生一张彩票。(它们是西班牙语,所以代码中的大多数内容都是。)如果用户输入的彩票名称不在choices变量中,如何使其重新启动代码 提前谢谢Python 选择后重新启动代码不在';选择';变量,python,Python,所以,我正试图为我的祖父母制作一个惊喜节目,产生一张彩票。(它们是西班牙语,所以代码中的大多数内容都是。)如果用户输入的彩票名称不在choices变量中,如何使其重新启动代码 提前谢谢 import random options = ("Bonoloto", "Primitiva", "Euromillón", "Gordo") reintegro = random.sample(range(1,9), 1) lo
import random
options = ("Bonoloto", "Primitiva", "Euromillón", "Gordo")
reintegro = random.sample(range(1,9), 1)
loteria = random.sample(range(1,50), 6)
boleto = sorted(loteria)
choice = input('Que lotería quieres jugar hoy? ')
if choice in options:
print('Tus numeros de', choice, 'son:', boleto, 'con reintegro', reintegro)
else:
print('Esa lotería no existe!')
将其包装成循环,并在成功时中断循环
while True:
choice = input('Que lotería quieres jugar hoy? ')
if choice in options:
print('Tus numeros de', choice, 'son:', boleto, 'con reintegro', reintegro)
break
else:
print('Esa lotería no existe!')
将其包装成循环,并在成功时中断循环
while True:
choice = input('Que lotería quieres jugar hoy? ')
if choice in options:
print('Tus numeros de', choice, 'son:', boleto, 'con reintegro', reintegro)
break
else:
print('Esa lotería no existe!')
您需要使用一个循环-在这里,while循环是完美的:
import random
options = ("Bonoloto", "Primitiva", "Euromillón", "Gordo")
reintegro = random.sample(range(1,9), 1)
loteria = random.sample(range(1,50), 6)
boleto = sorted(loteria)
while True:
choice = input('Que lotería quieres jugar hoy? ')
if choice in options:
print('Tus numeros de', choice, 'son:', boleto, 'con reintegro', reintegro)
break
else:
print('Esa lotería no existe!')
此代码将继续询问彩票名称,直到他们在列表中选择一个为止您需要使用循环-while循环在这里非常完美:
import random
options = ("Bonoloto", "Primitiva", "Euromillón", "Gordo")
reintegro = random.sample(range(1,9), 1)
loteria = random.sample(range(1,50), 6)
boleto = sorted(loteria)
while True:
choice = input('Que lotería quieres jugar hoy? ')
if choice in options:
print('Tus numeros de', choice, 'son:', boleto, 'con reintegro', reintegro)
break
else:
print('Esa lotería no existe!')
此代码将继续询问彩票名称,直到他们在列表中选择一个使用循环-一个while循环是个好主意-查看我的答案使用循环-一个while循环是个好主意-查看我的答案谢谢!您还知道我如何生成自定义数量的票证吗?我会将实际生成票证的代码包装到一个函数中,然后根据需要多次调用该函数。非常感谢!您还知道我如何生成自定义数量的票证吗?我会将实际生成票证的代码包装到一个函数中,然后根据需要多次调用该函数。谢谢!您还知道如何根据请求重新启动代码(通过询问用户是否希望重新启动)或如何生成多个票证吗?提前谢谢@MadeByAlvaropop将所有代码放在一个循环中。检查重启选项。谢谢!您还知道如何根据请求重新启动代码(通过询问用户是否希望重新启动)或如何生成多个票证吗?提前谢谢@MadeByAlvaropop将所有代码放在一个循环中。检查重启选项。