获取类型错误:无法将“float”对象隐式转换为str?

2024-10-01 15:44:38 发布

您现在位置:Python中文网/ 问答频道 /正文

这是GCSE项目的一部分,请帮助我正确地使用这部分代码。 这是两个角色之间的一场“相遇”游戏

import random

tryagain = "Y" or "y"


char1name = input(str("character 1 please enter your name "))
char2name = input(str("character 2 please enter your name "))

print ("Player 1, your name is " + char1name)
print ("Player 2, your name is " + char2name)
print ("  ")
player1skill = input(str("what is your skill level " + char1name + "? "))
player2skill = input(str("what is your skill level " + char2name + "? "))
player1strength = input(str("what is your strength level " + char1name + "? "))
player2strength = input(str("what is your strength level " + char2name + "? "))

print (char1name + " has a skill of " + player1skill + " and a strength of " +  player1strength)
print (char2name + " has a skill of " + player2skill + " and a strength of " +  player2strength)

if (int(player1strength) >= int(player2strength)):
    strength_modifier = ((int(player1strength)) - (int(player2strength)))
else:
    strength_modifier = (int(player2strength) - (int(player1strength)))

if (int(player1skill) >= int(player2skill)):
    skill_modifier = ((int(player1skill)) - (int(player2skill)))
else:
    skill_modifier = (int(player2skill) - (int(player1skill)))
print("The strength modifier is " + (int(strength_modifier) / (int(5))))
print("The skill modifier is " + (int(skill_modifier) // (int(5))))

roll_player1 = random.randint(1,6)
roll_player2 = random.randint(1,6)

if int(roll_player1) == int(roll_player2):
    print("no changes are made")
else: print(char1name +"'s skill has gone up to " + (str(player1skill) +  str(skill_modifier)))
print("and their strength has gone up to" + (int(player1strength) + int(strength_modifier)))
if int(roll_player1) <= int(roll_player2):
    print(char2name + "'s skill has gone up to " + (int(player2skill) +  int(skill_modifier)))
    print("and their strength has gone up to" + (int(player2strength) +       int(strength_modifier)))

这是我一直得到的错误,有什么问题??在

^{pr2}$

Tags: inputyourisstrengthskillintprintmodifier

热门问题