Почему этот код python не выполняется полностью? - PullRequest
0 голосов
/ 21 апреля 2020

Когда я запускаю следующий код в pycharm, он выполняется до ans = input («Хочешь играть в эту игру»), а когда я набираю answer yes, в идеале должен выполняться приведенный ниже код, но он выполняет print ('Спасибо так много для игры, вы получили », оценка,« вопросы правильные »)

print ("Welcome to the page?")

ans = input("Do you want to play this game? Yes/No")
score = 0

if ans.lower()=='yes':
   ans=input("When was Bangalore made capital city of Karnataka?")
   if ans.lower()=="1956":
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans=input("Who is the current Mayor of Bangalore?")
   if ans.lower()=="M Goutham Kumar":
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans=input("What is the GDP of Bangalore?")
   if ans.lower()=="$210 Billion":
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans = input("Who is called as father of Bangalore?")
   if ans.lower() == "Kempegowda":
      score = +1
      print("Correct + 1")
   else:
      print("In-correct")

print('Thank you so much for playing, you got', score, 'questions correct')

Ответы [ 2 ]

1 голос
/ 21 апреля 2020

На самом деле, ваш код работает. Но, возможно, вы вводите пробел после или перед словом. Или, может быть, на Linux, есть ввод ans\r.

print ("Welcome to the page?")

ans = input("Do you want to play this game? Yes/No ")
score = 0

if ans.lower().strip()=='yes':
   ans=input("When was Bangalore made capital city of Karnataka? ")
   if int(ans)==1956:
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans=input("Who is the current Mayor of Bangalore? ")
   if ans.lower().strip()=="m goutham kumar":
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans=input("What is the GDP of Bangalore? ")
   if ans.lower().strip()=="$210 billion":
      score=+1
      print("Correct + 1")
   else:
      print("In-correct")

   ans = input("Who is called as father of Bangalore? ")
   if ans.lower().strip() == "Kempegowda":
      score = +1
      print("Correct + 1")
   else:
      print("In-correct")

print('Thank you so much for playing, you got', score, 'questions correct')
0 голосов
/ 21 апреля 2020
print ("Welcome to the page?")

ans = input("Do you want to play this game? Yes/No")


score = 0

if ans.lower()=='yes':

   ans=input("When was Bangalore made capital city of Karnataka?")

   if ans.lower()=="1956":

      score=+1

      print("Correct + 1")

   else:

      print("In-correct")

   ans=input("Who is the current Mayor of Bangalore?")

   if ans.lower()=="M Goutham Kumar":

      score=+1

      print("Correct + 1")

   else:

      print("In-correct")

   ans=input("What is the GDP of Bangalore?")

   if ans.lower()=="$210 Billion":

      score=+1

      print("Correct + 1")

   else:

      print("In-correct")

   ans = input("Who is called as father of Bangalore?")

   if ans.lower() == "Kempegowda":

      score = +1

      print("Correct + 1")

   else:

      print("In-correct")

print('Thank you so much for playing, you got', score, 
'questions correct')
...