2014-03-25 1 views
-1

이것은 내 GCSE 컴퓨팅 코드 프로젝트의 일부이며 올바르게 작동하려면 제대로 작동하지 않습니다. 두 문자TypeError 받기 : 'float'객체를 암시 적으로 str로 변환 할 수 없습니까?

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))) 

이 문제 제가가 계속 오류입니다 사이의 '만남'게임으로 의미?

character 1 please enter your name player1 
character 2 please enter your name player2 
Player 1, your name is player1 
Player 2, your name is player2 

what is your skill level player1? 10 
what is your skill level player2? 5 
what is your strength level player1? 20 
what is your strength level player2? 10 
player1 has a skill of 10 and a strength of 20 
player2 has a skill of 5 and a strength of 10 
Traceback (most recent call last): 
    File "\\fileserver-01\studenthome$\*serverlocation* 
line 29, in <module> 
    print("The strength modifier is " + (int(strength_modifier)/(int(5)))) 
TypeError: Can't convert 'float' object to str implicitly 
+0

이미 대답 - 두 http://stackoverflow.com/questions/13654168/typeerror-cant-convert-int-object-to-str-implicitly?rq=1 – jaime

답변

1

이 작업의 결과 :

(int(strength_modifier)/(int(5))) 

는 부동입니다. 이를 문자열로 변경하려면 문자열로 변환하십시오.

str(int(strength_modifier)/(int(5))) 
+0

분할'int'가 반환하는 '떠 다니는거야? ' – CoryKramer

+0

@Cyber ​​in Python3 –

+0

@Cyber ​​네, 분명히 그렇습니다. Python 3 – aIKid

관련 문제