1

Please help :)

Write a program to collect input from the user for two complete addresses (name, street number, street name, city, state, and zip code) from the command-line prompt. You will first need to create variables to store the addresses in the variables, and then create the appropriate built-in functions to capture the input from the addresses from the user. The street number and zip must be represented in the system as numerical values. Create a program that captures user input and uses variables to store the addresses to be printed.

I know I need to use eval(input()) to convert the characters to numerical values.

I have this as an outline in python for mac currently, just need to enter the information but I am stuck on what "\n" means. as well as where to enter the information.

#user input for first address
print ("\nEnter first address")
name1 = input("Name: ")
streetName1 = input("Street Name: ")
streetNumber1 = input("Street Number: ")
city1 = input("City: ")
#user input for first address
print ("\nEnter first address")
name1 = input("Name: ")
streetName1 = input("Street Name: ")
streetNumber1 = input("Street Number: ")
city1 = input("City: ")
state1 = input("State: ")
zip1 = input("Zip Code: ")
#user input for first address
print ("\nEnter second address")
name2 = input("Name: ")
streetName2 = input("Street Name: ")
streetNumber2 = input("Street Number: ")
city2 = input("City: ")
state2 = input("State: ")
zip2 = input("Zip Code: ")

print both address

print ("\nFirst address is :")
print ("Name", name1)
print ("Street Name", streetName1)
print ("Street Number", streetNumber1)
print ("City", city1)
print ("State", state1)
print ("Zip Code", zip1)

print ("\nSecond address is :")
print ("Name", name2)
print ("Street Name", streetName2)
print ("Street Number", streetNumber2)
print ("City", city2)
print ("State", state2)
print ("Zip Code", zip2)
program123
  • 11
  • 4
  • Which part are you stuck on? Please provide a [mcve]. – jpaugh Feb 12 '18 at 23:16
  • Please, read [How do I ask and answer homework questions?](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions) – JP Ventura Feb 12 '18 at 23:17
  • 1
    I'll note that you don't want to use `eval()`, but `int()` to convert string to an integer, not just for security reasons, but also because [Zip Codes starting with zero will not be converted](https://stackoverflow.com/a/45881590/1270789)! – Ken Y-N Feb 12 '18 at 23:25
  • 1
    I just updated my question to have the outline of the code and explained where I am stuck at within the code. I am sorry for not posting properly this is my first time here and I am learning the ways – program123 Feb 12 '18 at 23:26
  • this was provided by professor as an example: myname = input("Name: ") myage = eval(input("Age: ")) mysalary = eval(input("Salary: ")) print ("My name is", myname) print ("I am", myage) print ("I earn", mysalary) – program123 Feb 12 '18 at 23:27
  • You can demonstrate to your professor that `eval('01234')` returns a "SyntaxError: invalid token" error, if you feel up to it! Otherwise, since the prof says to use `eval()`, I suppose you'd better. Anyway, I'm still not clear on your question; `zip2 = eval(input("Zip Code: "))` seems to be what you want? (Oh, and you should really use a list `zip[0]` and `zip[1]` rather than individual variables). And as for your actual question, `\n` prints a new line. – Ken Y-N Feb 12 '18 at 23:40
  • I will definitely demonstrate to my professor it returns with a SyntaxError, as well and will use a list instead of individual variables. I suppose my main question, I do not know where/how to convert characters into numbers. – program123 Feb 12 '18 at 23:46

1 Answers1

0

Python 3.x does not evaluate, you need to use int() at the time of getting and storing the user input like below:

streetNumber1 = int(input("Street Number: ")) zip1 = int(input("Zip Code: "))