【发布时间】:2014-04-13 16:15:04
【问题描述】:
这是我正在处理的整个程序(由于代码需要缩进,该函数不在正确的位置)但无论如何存在一个我不确定如何解决的问题。
如何更改它以使其与我的程序一起使用?它说它在一个字符串中,但不确定如何更改它,因此它从我的程序的其余部分计算变量。很抱歉,这似乎不是唯一的问题,我对此并不陌生,而且刚刚习惯了它的工作原理。
import time
import random
def welcome():
ready="no"
while ready=="no":
print("Welcome To Encounter Simulator Inc. Where We Provide You with combat..")
print("Readying Start Up Sequence....")
time.sleep(0.5)
print("Welcome Are You Ready? Yes or No")
ready=input(str())
while ready!="yes" and ready!="no":
print("Yes or No Please")
ready=input(str())
def name():
areyousure="no"
while areyousure!="yes":
print("What do you want your 1st character to be named?")
name=input()
print("Are You Sure?(yes or no)")
areyousure=input(str())
if areyousure!="yes" and areyousure!="no":
print("Yes or No Please")
areyousure=input(str())
return name
def name2():
areyousure2="no"
while areyousure2!="yes":
print("What do you want your 2nd character to be named?")
name2=input()
print("Are You Sure?(yes or no)")
areyousure2=input(str())
if areyousure2!="yes" and 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 You 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 You 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 Will Be 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 Will Be No Strength Modifier")
result2=0
else:
result10=strength2-strength1
result2=result10/5
return result2
def dicerolling1():
print()
time.sleep(1)
print("This Will Determin Who Gets The Modifiers And Who Loses Them..")
dicenumber1=random.randint(1,6)
print(" The Dice Is Rolling For",name1,)
time.sleep(1)
print("And The Number",name1,"Got Was...",dicenumber1,)
return dicenumber1
def dicerolling2():
print()
time.sleep(1)
print("This Will Determin Who Gets The Modifiers And Who Loses Them..")
dicenumber2=random.randint(1,6)
print(" The Dice Is Rolling For",name2,)
time.sleep(1)
print("And The 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()
【问题讨论】:
-
您面临的具体问题是什么?错误在哪里?请在您对问题的解释中明确说明。
-
它说不支持的操作数在字符串中使用 - 但不知道如何修复等
-
skill1和skill2是字符串吗?如果是这样,您需要将它们转换为数字。 -
哦,是的,谢谢,这可能是问题所在!
-
请给出 1.)
difference1的至少 1 个输入示例,2.) 对于这些示例,difference1的预期输出,3.) 错误/回溯的复制/粘贴.目前,尚不清楚您要问什么以及确切的错误是什么。
标签: python string python-3.x