python - How do I change a sum for string for it to work? -
this whole program i'm working on (with function not in right place due code needing indented) anyway there problem i'm not sure how fix.
how change work along program? says in string not sure how change calculates variables rest of program. sorry seeming how not problem new , getting used how works.
import time import random def welcome(): ready="no" while ready=="no": print("welcome encounter simulator inc. provide combat..") print("readying start sequence....") time.sleep(0.5) print("welcome ready? yes or no") ready=input(str()) while ready!="yes" , ready!="no": print("yes or no please") ready=input(str()) def name(): areyousure="no" while areyousure!="yes": print("what want 1st character named?") name=input() print("are sure?(yes or no)") areyousure=input(str()) if areyousure!="yes" , areyousure!="no": print("yes or no please") areyousure=input(str()) return name def name2(): areyousure2="no" while areyousure2!="yes": print("what want 2nd character named?") name2=input() print("are sure?(yes or no)") areyousure2=input(str()) if areyousure2!="yes" , areyousure2!="no": print("yes or no please") areyousure2=input(str()) return name2 def inputtingfor1(name): areyousure3="no" while areyousure3!="yes": print("please input",name,"'s attributes..") skill1=input("the skill attribute= ") strength1=input("the strength attribute= ") print("are sure? (yes or no)") areyousure3=input(str()) return skill1,strength1 def inputtingfor2(name2): areyousure4="no" while areyousure4!="yes": print("please input",name2,"'s attributes..") skill2=input("the skill attribute= ") strength2=input("the strength attribute= ") print("are sure (yes or no)") areyousure4=input(str()) return skill2,strength2 def difference1(skill1,skill2): if skill1 >= skill2: result0=skill1-skill2 result1=result0/5 elif skill1==skill2: print("there no skill modifier") result1=0 else: result0=skill2-skill1 result1=result0/5 return result1 def difference2(strength1,strength2): if strength1 >= strength2: result10=strength1-strength2 result2=result10/5 elif strength1==strength52: print("there no strength modifier") result2=0 else: result10=strength2-strength1 result2=result10/5 return result2 def dicerolling1(): print() time.sleep(1) print("this determin gets modifiers , loses them..") dicenumber1=random.randint(1,6) print(" dice rolling for",name1,) time.sleep(1) print("and number",name1,"got was...",dicenumber1,) return dicenumber1 def dicerolling2(): print() time.sleep(1) print("this determin gets modifiers , loses them..") dicenumber2=random.randint(1,6) print(" dice rolling for",name2,) time.sleep(1) print("and number",name2,"got was...",dicenumber2,) return dicenumber2 welcome() name=name() name2=name2() skill1,strength1=inputtingfor1(name) skill2,strength2=inputtingfor2(name2) difference1(skill1,skill2) difference2(strength1,strength2) dicenumber1=dicerolling1() dicenumber2=dicerolling2()
from comment thread on original question, issue skill1
, skill2
strings, not support -
operand. need cast them ints
before perform mathematical operation on them:
def difference1(skill1,skill2): try: s1 = int(skill1) s2 = int(skill2) except exceptions.valueerror: print("could not cast int") return none if s1 >= s2: result0 = s1-s2 result1=result0/5 elif s1==s2: print("there no skill modifier") result1 = 0 else: result0=s2-s1 result1=result0/5 return result1
depending on pass difference1
, may not left integer. if skill1
, skill2
parsed floats
, you'll hit exception when try cast them ints
. if know never case, can remove try-except
block.
Comments
Post a Comment