lundi 19 mars 2018

Why won't my if, else statment work in python in the while loop

My If/else statements are not working in my while loop. The purpous of this program is "for the user to enter a number, print every number leading up to it, tell if the number is even or odd, print the sum. And then have the user enter if he wants to repeat the process or not" Here is the source code (Keep in mind that I am a student and very new to coding):

print("Christian Dooley")
print("Lab #5")
import sys

def calculation():
 counter = 0
 NumberOfElements = 1
 numbers = []
 sum = (0)
 for i in range(NumberOfElements):
     value=eval(input("Enter a new number:"))
     numbers.append(value)
 while counter <= value:
     print(counter)
     sum+=counter
     counter+=1
     if counter % 2 != 0:
         print("This number is even")
     else:
         print("This number is odd")
 print(sum)

while True:
 calculation()
 repeat = input("Do you want to 'count' another number \n Awnser yes or no: ")
 if repeat == "Yes" or "yes":
      calculation()
 elif repeat == str("no") or str("No"):
      break

This is the part of the code that is giving me trouble:

if repeat == "Yes" or "yes":
          calculation()
     elif repeat == str("no") or str("No"):
          break

The if statement will keep running over and over, no matter what I enter for the repeat variable, can anyone tell me why.

Aucun commentaire:

Enregistrer un commentaire