Home > Net >  Beginner Programming: How to print mailing address & add spaces in python?
Beginner Programming: How to print mailing address & add spaces in python?

Time:09-10

I'm trying to ask the user to enter in their mailing address information, storing their first name, last name, street address (line 1), room number, city, state, and ZIP as variables.

I'm struggling.

Also how do you add spaces in between words on Python?

The last line is not coming together for some reason...

city = "Atlanta"
state = "Georgia"
zip_code = "30002"

first_name = input("Enter first name:")
last_name = input("Enter last name:")
address_1 = input("Enter mailing address:")
address_2 = input("Enter room number:")
print(first_name   last_name, "mailing address is:")
print(address_1)
print(address_2)
print(city   ","   state,   zip_code)

And how to add spaces in between words?

CodePudding user response:

Check out f-strings.

print(f"{city}, {state} {zip_code}")

CodePudding user response:

city = "Atlanta"
state = "Georgia"
zip_code = "30002"

first_name = input("Enter first name:")
last_name = input("Enter last name:")
address_1 = input("Enter mailing address:")
address_2 = input("Enter room number:")
print(first_name   last_name, "mailing address is:")
print(address_1)
print(address_2)
print(city   ', '   ''   state   ', '   zip_code)

CodePudding user response:

using "," will add space automatically example

print(first_name, last_name, "mailing address is:")
print(city, state,  zip_code)

or much better way will be using f-string like:

print(f"city is: {city} State is: {state} Zip-Code is: {zip_code}")

variables are between curly braces and string is out side of it

  • Related