import random
import time
global score
global cpuscore
score = 1
cpuscore = 1
print("Current score CPU:Player = 1 , 1 ")
def plus():
rand1 = random.randint(2,99)
rand2 = random.randint(2,99)
ans = (rand1 + rand2)
print("What's", rand1, "+" ,rand2,)
quest = int(input())
if quest == ans:
print("Correct")
score + 1
else:
print("Incorrect")
cpuscore + 1
def multiply():
rand1 = random.randint(2,99)
rand2 = random.randint(2,99)
ans = (rand1 + rand2)
print("What's", rand1, "+" ,rand2,)
quest = int(input())
if quest == ans:
print("Correct")
score + 1
else:
print("Incorrect")
cpuscore + 1
def subtract():
rand1 = random.randint(2,99)
rand2 = random.randint(2,99)
ans = (rand1 + rand2)
print("What's", rand1, "+" ,rand2,)
quest = int(input())
if quest == ans:
print("Correct")
score + 1
else:
print("Incorrect")
cpuscore + 1
print("Welcome to eleven elves")
print("Please name your elves")
elf1 = input("Elf 1: ")
elf2 = input("Elf 2: ")
elf3= input("Elf 3: ")
elf4 = input("Elf 4: ")
elf5 = input("Elf 5: ")
elf6 = input("Elf 6: ")
elf7 = input("Elf 7: ")
elf8 = input("Elf 8: ")
elf9 = input("Elf 9: ")
elf10 = input("Elf 10: ")
elf11 = input("Elf 11: ")
print("So let me just clarrify, the name of your eleven elves throughout this quest will be")
clar = str.lower(input("Is this correct? (Yes or No) "))
if clar == ("yes"):
print("Ok, let's continue on")
else:
print("Would you to change the name of your elves?")
clar2 = str.lower(input("Yes or No "))
if clar2 == ("yes"):
elf1 = input("Elf 1: ")
elf2 = input("Elf 2: ")
elf3= input("Elf 3: ")
elf4 = input("Elf 4: ")
elf5 = input("Elf 5: ")
elf6 = input("Elf 6: ")
elf7 = input("Elf 7: ")
elf8 = input("Elf 8: ")
elf9 = input("Elf 9: ")
elf10 = input("Elf 10: ")
elf11 = input("Elf 11: ")
print("Elf names changed.")
else:
print("Ok no problem, let's continue on")
print(elf1, "enters a cave... The cave is full of monsters and creepy crawlys, a monster pops out of no where, the monster says.. Dear old dear old", elf1 ,"Why are you all by your self? You wanna get past, you gotta' get asked do you accept or run away?")
q1 = str.lower(input("Do you accept the challenge... ('you get the drift now yes or no....') "))
if q1 == ("yes"):
plus()
print("Current score CPU:Player", cpuscore, score)
else:
print(elf1, "runs away")
print(cpuscore)
"cpuscore"에 1을 더하는 것과 같은 방식으로 "score"에 1을 더하고 싶습니다. 코드를 수정하고 올바른 질문을 얻으면 여전히 새로운 점수를 1로 인쇄하므로 혼란스럽고 그 이유를 알 수 없습니다. 나는 파이썬에 익숙하지 않아서 정말 도움이되지 않을 것이다.누군가 내 코드 (파이썬 함수)를 도와 줄 수 있습니까?
는문제는 여전히
Traceback (most recent call last):
File "N:\Open Me x\Computing\Mrs Farakh\Programming\Python\Assessment.py", line 139, in <module>
plus()
File "N:\Open Me x\Computing\Mrs Farakh\Programming\Python\Assessment.py", line 27, in plus
score += 1
UnboundLocalError: local variable 'score' referenced before assignment
코드 스 니펫이 추적 코드와 일치하지 않습니다. 게시물을 수정하여 문제를 명확히하십시오. –
나는 Bhat Irshad의 대답을 구현하려고했을 때 일어났던 일을 "이 문제는 여전히 지속된다"는 진술과 추적보고가 설명한다고 생각한다. 대답이 잘못 되었기 때문에 의미가 있습니다. –