1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with a simple Python program

  1. Jun 15, 2013 #1
    1. The problem statement, all variables and given/known data
    Hello. I want to write a program which finds the largest number in the sequence typed in by the user. However, when I type in a number it not only gets printed as the input value but gets re-printed as if I have done the print function of that number (though the final answer is correct). How can I solve this issue and make the program cleaner?

    2. The attempt at a solution
    Code (Text):
    seq = [0]
    n = int(input("Start typing the sequence (end it with 0)"))
    while (n!=0):
            n = int(input(n))
            seq = seq + [n]
    print ("The largest number in the sequence is " + str(max(seq)))
     
     
  2. jcsd
  3. Jun 15, 2013 #2

    jedishrfu

    Staff: Mentor

    try entering the numbers on one line and use the .split(" ") to separate them into an array of values
     
  4. Jun 15, 2013 #3

    Ibix

    User Avatar
    Science Advisor

  5. Jun 15, 2013 #4
    How do I enter them in one line? Why does the 'input' function force the numbers to be written in different lines?
     
  6. Jun 15, 2013 #5
    ----- Solved it. Thanks for the help.
     
    Last edited: Jun 15, 2013
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Help with a simple Python program
Loading...