accepting multiple user input

0 Natalie Ieyoub · August 16, 2015
I took a course in C++ and now I'm trying to practice some python after watching all of Bucky's videos on youtube. To practice I've been recreating C++ assignments into python but I'm having a little trouble with this one. It requires that you take 5 numbers that the user inputs and returns the average, only I dont know how to take in multiple values at once. Here is what that part of the assignment  looks like in C++:

float num1, num2, num3, num4, num5, total, average;

/*First prompt the user to enter five numbers.*/
cout<<"Please enter five numbers."<<endl;
cin>>num1>>num2>>num3>>num4>>num5;

can this be recreated in Python?



Post a Reply

Replies

Oldest  Newest  Rating
0 Otto Von Chesterfield · August 17, 2015
I'm not exactly sure what you want, since I'm not all too familiar with the C family, but I have a rough idea.


If the user inputs five numbers at a time, do this:
nums = [] #Create an empty list

print("Please enter five numbers.")

for _ in range(5):
 nums.append(int(input())) #Asks for a number, converts it into an integer and adds it to the nums list.

Tell me if this helps!
  • 1

Python

106,995 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator