为什么这段代码不起作用?

时间:2016-10-18 17:34:58

标签: python python-3.x

我目前正在为学校做一个我应该做骰子游戏的项目。这是代码:

Roll = input("Do you want to Roll or Stick?")
if Roll in ("Roll" , "roll"):
    print("Your new numbers are," , +number10 , +number20 , +number30 , +number40 , +number50)

KeepDelete = input("Would you like to keep or delete a number?")
if KeepDelete in("Keep", "keep"):
    print("Your numbers are," , +number10 , +number20 , +number30 , +number40 , +number50)
print("Your final score is," , number10+number20+number30+number40+number50)
if KeepDelete in("Delete", "delete"):
    Delete = int(input("What number would you like to delete?"))

if Delete == (number10):
    del(number10)
Score1 = int("Your numbers are" , number100 , number20 , number30 , number40 , number50)
print("Your final score is" , +number100 + number20 + number30 +number40 + number50)

if Delete == (number20):
   del(number20)
Score2 = int("Your numbers are" , number10 , number200 , number30 , number40 , number50)
print("Your final score is" , +number10 + number200 + number30 + number40 + number50)

if Delete == (number30):
    del(number30)
Score3 = int("Your numbers are" , number10 , number20 , number300 , number40 , number50)
print("Your final score is" , +number10 + number20 +number300 + number40 + number50)

if Delete == (number40):
    del(number40)
Score4 = int("Your numbers are" , number10 , number20 , number30 , number400 , number50)
print("Your final score is" +number10 + number20 + number30 + number400 + number50)

if Delete == (number50):
    del(number50)
Score5 = int("Your numbers are" , number10 , number20 , number30 , number40 , number500)
print("Your final score is" +number10 + number20 + number30 + number40 + number500)

以下是错误代码:

Score1 = int("Your numbers are" , number100 , number20 , number30 , number40 , number50)
TypeError: int() takes at most 2 arguments (6 given)

很抱歉这么长的一块,但我已经困惑了大约六个小时。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

只需获取代码的一部分:

insert into device_data (device_id, device_data) values
    ('first', 'data 1'),
    ('second', 'data 1'),
    ('first', 'data 2'),
    ('second', 'data 2');

select * from device_data_first;

 id | device_id | device_data |        received_at         
----+-----------+-------------+----------------------------
  1 | first     | data 1      | 2016-10-18 19:50:40.179955
  3 | first     | data 2      | 2016-10-18 19:50:40.179955
(2 rows)

select * from device_data_second;

 id | device_id | device_data |        received_at         
----+-----------+-------------+----------------------------
  2 | second    | data 1      | 2016-10-18 19:50:40.179955
  4 | second    | data 2      | 2016-10-18 19:50:40.179955
(2 rows)

int()将参数转换为整数格式。错误消息告诉您它需要两个参数:1)要转换的值和2)基数。

所以:

print("Your final score is," , number10+number20+number30+number40+number50)
if KeepDelete in("Delete", "delete"):
    Delete = int(input("What number would you like to delete?"))

if Delete == (number10):
    del(number10)
Score1 = int("Your numbers are" , number100 , number20 , number30 , number40 , number50)
print("Your final score is" , +number100 + number20 + number30 +number40 + number50)

您正在尝试将参数Delete = int(input("What number would you like to delete?")) 强制转换为整数。

在您收到的具体错误消息中,您尝试将input("What..."))和所有后续变量投射到"your numbers are",然后将其传递给变量得分1。 Python并不知道从哪里开始。

您可以在Python Docs找到更多信息。