Help with a simple Python program

In summary, the user is trying to write a program that finds the largest number in a sequence inputted by the user. However, when they input a number, it gets re-printed along with the correct answer. The solution is to enter the numbers on one line and use the .split(" ") function to separate them into an array of values. The argument for the input() function should be the prompt, not the variable. The issue was solved by following the relevant information in the Python documentation.
  • #1
2sin54
109
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
  • #2
try entering the numbers on one line and use the .split(" ") to separate them into an array of values
 
  • #4
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?
 
  • #5
----- Solved it. Thanks for the help.
 
Last edited:

1. What is Python used for?

Python is a popular programming language used for a variety of applications such as web development, data analysis, artificial intelligence, and automation. It is known for its simplicity, readability, and versatility.

2. How can I get help with a simple Python program?

There are several resources available for getting help with a simple Python program. You can consult online tutorials and documentation, join online communities and forums, or seek help from a mentor or tutor.

3. I am new to programming, is Python a good language to start with?

Yes, Python is considered to be a great language for beginners due to its simple syntax, easy-to-learn nature, and strong community support. It also has a wide range of applications, making it a valuable skill to learn.

4. What are the basic concepts I need to know to understand a simple Python program?

To understand a simple Python program, you should have a basic understanding of concepts such as variables, data types, control structures (if/else statements, loops), functions, and basic syntax. It is also helpful to have a basic understanding of object-oriented programming.

5. How can I improve my Python programming skills?

To improve your Python skills, it is important to practice regularly and work on different projects. You can also read books and articles, watch online tutorials, and participate in coding challenges. Additionally, seeking feedback and learning from experienced programmers can also help improve your skills.

Similar threads

Replies
9
Views
1K
  • Programming and Computer Science
Replies
29
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
22
Views
757
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
2
Replies
55
Views
4K
Replies
1
Views
648
Back
Top