#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Neep help on my code :/ cant figure it out


    #Goal: Write a program that asks the user to input 10 integers, and then
    #prints the largest odd number that was entered. If no odd number was
    #entered, it should print a message to that effect.

    #Intro

    print 'List 10 diffrent odd numbers and see which one is biggest!'

    #List of inputs for odd variables

    a = raw_input ('Print odd number 1! ')
    s = raw_input ('Print odd number 2! ')
    d = raw_input ('Print odd number 3! ')
    f = raw_input ('Print odd number 4! ')
    g = raw_input ('Print odd number 5! ')
    h = raw_input ('Print odd number 6! ')
    j = raw_input ('Print odd number 7! ')
    k = raw_input ('Print odd number 8! ')
    l = raw_input ('Print odd number 9! ')
    p = raw_input ('Print odd number 10! ')

    #Commands to compare numbers
    #See which is biggest and if they are odd

    if (a > s and a > d and a > f and a > g and a > h and a > j and a > k and a > l and a > p ) and (a % 2 != 0):
    print str(a) + ' is the greatest odd'
    elif (s > a and s > d and s > f and s > g and s > h and s > j and s > k and s > l and s > p ) and (s % 2 != 0):
    print str(s) + ' is grandest of the odds'
    elif (d > s and d > a and d > f and d > g and d > h and d > j and d > k and d > l and d > p ) and (d % 2 != 0):
    print str(d) + ' rules the odds'
    elif (f > s and f > d and f > a and f > g and f > h and f > j and f > k and f > l and f > p ) and (f % 2 != 0):
    print str(f) + ' is the champion'
    elif (g > s and g > d and g > f and g > a and g > h and g > j and g > k and g > l and g > p ) and (g % 2 != 0):
    print str(g) + ' is the victor'
    elif (h > s and h > d and h > f and h > g and h > a and h > j and h > k and h > l and h > p ) and (h % 2 != 0):
    print str(h) + ' is the biggest adn baddest'
    elif (j > s and j > d and j > f and j > g and j > h and j > a and j > k and j > l and j > p ) and (j % 2 != 0):
    print str(j) + ' is the most enormus'
    elif (k > s and k > d and k > f and k > g and k > h and k > j and k > a and k > l and k > p ) and (k % 2 != 0):
    print str(k) + ' is the oddest giant'
    elif (l > s and l > d and l > f and l > g and l > h and l > j and l > k and l > a and l > p ) and (l % 2 != 0):
    print str(l) + ' is bigger than all the other odds'
    elif (p > s and p > d and p > f and p > g and p > h and p > j and p > k and p > l and p > a ) and (p % 2 != 0):
    print str(p) + ' is the best! odd number'

    #The else clause that occurs if all numbers are even or 2 of the same numbers have been listed

    else:
    print 'Try again, somethings wrong'

    #There is a problem running the program unfortunatly and I don't know how to
    #make the program more consise.. help plz
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    191
    Rep Power
    2
    Well you have put in quite a bit of work but unfortunately are headed in the wrong direction.

    When asking to do the same thing repeatedly you need to use a loop. When checking the validity of an input you also need to use a loop. For checking if a number is the maximum in a sequence of numbers the builtin max would be indicated.

    This is the answer but please take the time to actually understand the following code:
    python Code:
    user_inputs = []
    while len(user_inputs) < 10:
        while 1:
            remain = 10-len(user_inputs)
            prompt = "Please enter an inter ({} remaining): ".format(remain)
            try:
                user_inputs.append(int(raw_input(prompt)))
                break
            except ValueError:
                print("Invalid input")
    try:
        highest_odd = max(number for number in user_inputs if number%2)
        print("The largest odd integer was {}.".format(highest_odd))
    except ValueError:
        print("No odd numbers were entered.")
    raw_input("Press enter to exit")

    It should also obviously be turned into a function (or several functions) but I'm not sure if you have reached this point yet.
    -Mek
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Thanks!


    I am now learning and trying to get to that level , thank you for your help I truly appreciate it

IMN logo majestic logo threadwatch logo seochat tools logo