python3是否兼容python2_使之与Python3和2兼容

我试图建立一个抽奖系统,让你选择参与者,然后打印到屏幕上。我想让它与Python3和Python2交叉兼容。我对输入有问题。在要求您输入参与者姓名的地方输入的信息总是给我一个错误:

Traceback (most recent call last):

File "employee-raffle.py", line 20, in

participant_list.append(input("Enter person " + str(len(participant_list) + 1) + ": "))

File "", line 1, in

NameError: name 'test' is not defined

起始代码:# Import modules

import time

import random

print("Welcome to the raffle ")

participants = 0

# Checks how many people are participating in the raffle

while True:

try:

participants = int(input("\nHow many people are there in the raffle? \n"))

break

except:

print("Invalid option")

continue

# Creates a list and asks user to input the names of everyone

participant_list = []

while participants > len(participant_list):

participant_list.append(input("Enter person " + str(len(participant_list) + 1) + ": "))

# Chooses a random person

random_participant = participant_list[random.randint(0,len(participant_list ) - 1)]

# Prints the person to the screen

print("AND THE WINNER IS:")

print("3")

time.sleep(1)

print("2")

time.sleep(1)

print("1")

time.sleep(1)

print(random_participant)

它在python3中似乎工作得很好。我真的希望它能同时使用,因为我正在努力学习如何使事物交叉兼容,因为在我看来,这是一个重要的编程实践。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值