I need help to print this python program

person= {}

for prop in ['name', 'age', 'course']:

person[prop] = input('Please enter your %s: ' % prop)

print('{:<10} {:<10} {:<10}.format('NAME', 'AGE', 'COURSE'))

for key, value in student.items(): 
     name, age, course = value 
    print('{:<10} {:<10} {:<10}.format(name, age, course))

what is person?
What are you trying to achieve?
Please tell more about the question and expected solution
Wrap your code in triple backticks(```) for readability

Welcome, administrator1.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).


Please go back over your code to indent it correctly.

What I am trying to achieve is that I want to print the input values under the column namely: ‘NAME’, ‘AGE’, ‘COURSE’

Also, let assume I want the input to in the range of 10 persons or student, then all the input should be printed in a tabular form

  1. declare a dictionary
  2. create a loop to enter details for 10 times
    • You need a key and value to add into dictionary
      Let’s take serial number as a key and list of name, age, course as value
      as following
    name = input("Enter your name")
    ...
    details = [name, age, course]
    student[ i ] = details
    
  3. Your student dictionary should now be like
    {1: ["My Name", 21, "Python"], 2: ["Second Name", 24, "Javascript"]...}
    
  4. Print the headers in correct format and with required styling

print other rows as you’ve already done

For help with python Dictionaries visit W3Schools

Very helpful. Thanks.

But I would be glad if you can also give a hint on creating the loop for 10times since I’m a beginner.

Thanks

sorry, but I’m very bad at explaining things
you can learn loops at

After learning, you can ask your doubts if you have

<p>Python dictionary<\p>

I want the code to allow input space of 200max and print all input at any point in time in a tabular form

//
student = {}

name = input('please enter your name: ')
age= input('please enter your age: ')
Course = input('please enter your course: ')


details = [name, age, course]
student[0] = details

print('{:<10} {:<10} {:<10}'.format('NAME', 'AGE', 'COURSE'))

for key, value in student.items():
    name, age, course = value
    print('{:<10} {:<10} {<10}'.format(name, age, course))

While the above code works perfectly, it only store and print one input.

I need help to expand the input to 200max and print the available inputed value even if its not up to 200 input.

Thanks in advance

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

No help coming for my concern!

“”"

Space = int(input('please enter the number of student to be added: '))

for n in range(space):
        Student = [
                input('enter your name: '),
                input('enter your age: '),
                input('enter your course: ')
print(Student)

“”"

My question thus:

Let’s assume space is in range 3
It means that the user will input into Student 3times.

Now, why is my code only returning the last input and ignoring the first two input in the range?

Pls I need help!

Thanks

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

In your code, on every loop new Student variable is declared that is why you only see the last input. So in order to prevent that, you need to define your variable (in this case, student_list) outside of the variable, and on each loop, you add new student to the list.

space = int(input('please enter the number of student to be added: '))
student_list = []

for n in range(space):
    student = [
        input('enter your name: '),
        input('enter your age: '),
        input('enter your course: ')
    ]
    student_list.append(student)
print(student_list)

I hope you get it :wink:

PS: You should declare your normal variable with small letter. It improves your code’s readability and to follow convention.

1 Like

I have tried it and it gives me result I wanted.

Thanks

I’m finding it difficult to convert the result to dictionary.

Let’s say student list is in the range of 3 and everything should be in dictionary.

Thanks for your time and advice

I created a code using dictionary to ask for user input value into the following keys: Name, Age, Course. The code works very fine for 3 input.

However, I want to use break and continue statement to always ask users every time if the user want to enter more value or exit the program.

This is the code

details = {}

student1 = [
        input('enter your name: '),
        input('enter your age: '),
        input('enter your course: ')
        ]

student2 = [
        input('enter your name: '),
        input('enter your age: '),
        input('enter your course: ')
        ]

student3 = [
        input('enter your name: '),
        input('enter your age: '),
        input('enter your course: ')
        ]

classroom = {'student1 : student1,
                             'student2 : student2,
                            'student3 : student3
                           }

print('{:<10} {:<10} {:<10}'.format('NAME', 'AGE', 'COURSE'))

for key, value in classroom.items():
        student1, student2, student3 = value
        print('{:<10} {:<10} {:<10}'.format(student1, student2, student3))

I need idea for the program to be asking the user every time the user input the first value of name, age and course.

The user should be able to specify either to exit or continue.

Thanks

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Ask them, put that into a variable, and use a control statement to determine whether you should break or just go to the next line?

like:

print 'Do you want to continue? y or n'
answer = input()
if (answer ===   'y') break
input('enter your age: ')

Sorry, I don’t know Python so can’t be more specific.

Thanks for your time.
But I want the asking through the loop to come after the other user has completed input to the first name, age and course.

So the asking should come if the user wants to proceed in entering another value to the key name, age and course then ask again for the 3rd input.

Be reminded that I provided for 3 times of input like;

Student1(name, age, course), ‘ask if to break or continue’.

If break, print for student1 only.

If continue, then student2(name, age, course) then like that.

Thanks

if this is the actual code you are using, you have a lot of missing closing quotes, which makes it difficult to work