Help with a simple Python program

  • Context: Python 
  • Thread starter Thread starter 2sin54
  • Start date Start date
  • Tags Tags
    Program Python
Click For Summary

Discussion Overview

The discussion revolves around a Python programming issue related to user input handling in a program designed to find the largest number in a user-defined sequence. Participants explore how to improve the program's functionality and user experience.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant describes their initial problem where input numbers are printed again, despite the final output being correct.
  • Another participant suggests entering numbers on one line and using the .split(" ") method to separate them into an array.
  • A different participant points out that the argument to the input() function should be a prompt, not the variable intended to store the input.
  • A follow-up question is raised about how to enter numbers in one line and why the input function causes numbers to be entered on different lines.
  • A later reply indicates that the original poster has resolved their issue with the help provided.

Areas of Agreement / Disagreement

The discussion includes multiple suggestions for improving the program, but there is no explicit consensus on a single solution before the original poster resolves their issue.

Contextual Notes

Participants do not fully explore the implications of their suggestions, and there may be assumptions about the user's familiarity with Python functions and input handling.

2sin54
Messages
109
Reaction score
1

Homework Statement


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:
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)))
 
Technology news on Phys.org
try entering the numbers on one line and use the .split(" ") to separate them into an array of values
 
jedishrfu said:
try entering the numbers on one line and use the .split(" ") to separate them into an array of values

How do I enter them in one line? Why does the 'input' function force the numbers to be written in different lines?
 
----- Solved it. Thanks for the help.
 
Last edited:

Similar threads

Replies
1
Views
2K
Replies
9
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 28 ·
Replies
28
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
55
Views
7K