lundi 23 septembre 2019

While Loop integer Python

I am having trouble with this while loop assignment for class. We are asked to find

  1. The smallest and largest of the inputs.
  2. The number of even and odd inputs.
  3. Cumulative totals.
  4. All adjacent Duplicates

I can't get my counters to work properly, my total or my biggest and small variable. I have tried moving around my if statements and deleting some and when I do that something else goes wrong.

big = 0
small = 0
total = 0
even = 0
odd = 0
dupe = 0
#if statements to catch value at the beginning 
value = int(input("enter a number:"))

total = total + value
if value % 2 == 0:
    even += 1
elif value % 2 != 0:
    odd += 1

n = input("enter a number:")
if n == str(value):
    dupe += 1

value = int(n)

total = total + value

if value % 2 == 0:
    even += 1
elif value % 2 != 0:
    odd += 1
#while loop with a sentinel value of a blank space
while n!= "":

    if value % 2 == 0:
        even += 1
    elif value % 2 != 0:
        odd += 1
    if n == str(value):
        dupe += 1
    total = total + value
    if str(value) <= n:
        small = n
    elif str(value) >= n:
        big = value
#if statements to check for evens, odds , and smallest and largest value
    n = input("enter a value:")

print("odds:" , odd)
print("evens:", even)
print("total:" , total)
print("duplicates:", dupe)
print("largest number:" , big)
print("smallest number:", small)

Aucun commentaire:

Enregistrer un commentaire