Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code help!
#1
Hello Gurus,

I need some help with this experience that can help direct me to completing this exercise, however I need someone that can help me really understand the best approach to tackling this exercise.

1. 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. You will accomplish this using what you’ve learned in the first few weeks of this class. Create a program that captures user input and uses variables to store the addresses to be printed.

(This is what I think I need to do is create Two complete addresses:
Name, street number, street name, city, state, and zip code

Need to create variable to store the addresses in the variables, create the appropriate built-in functions to capture the input from addresses from the user.
The street number and zip much be represented in the system as numerical values.)



2.) Print a box like the one below.
*******************
* *
* *
*******************

I have part of this one but not sure how to complete it. This is what I have so far. I'm not sure how to close out the rectangle on the right side.
print(' * ' * 10)
print(' * ' * 1)
print(' * ' * 1)
print(' * ' * 10)


3.) Write a program that prints a giant letter A like the one below. Allow the user to specify how large the letter should be.

*
* *
* * * * *
* *
* *
Not really sure about this one.

Thanks in advance for your help and support. I appreciate all of your help! (Also I'm not sure why it's not keeping the format for the rectangle and the BIG A)

Regards,
Linda Smile
Reply
#2
We will not do the work for, you need to show us what you have attempted, even if it doesn't work. From there we can advise you on what you need to do to correct the problem.

Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. when pasting between the code tags, use the sequence "Ctrl + Shift + V" this should preserve the indentation. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply" button.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Quote:I'm not sure how to close out the rectangle on the right side.
Isn't there a key on your keyboard that moves the cursor but doesn't print anything nor display anything on your display? Cool

Quote:(Also I'm not sure why it's not keeping the format for the rectangle and the BIG A)
That's because you must put such text between the tag [output][/output] (button "insert output" on the toolbar. (Not sure if this is the same as your big A)
Output:
* * * * * ******* * * * *
If you ask the user to make it larger, you can ask "How large do you want your big A (number between 1 and 10)?" and use it to widen your like this:
Output:
* * * * * * * * * * ************* ******************* * * * * * * * *
Reply
#4
In programming, we also have the concept of a space character as well as visible characters.

You can print a space and, when using a monospaced font (where all characters take up the same amount of space on the screen/printer, e.g. i and m) you can align things just on the basis of the number of characters (be they spaces or asterisks in your case) to be output. print(" " * 10) will print ten spaces.

You need to use string concatenation or formatting of your output to mix the asterisks and spaces. Some basic arithmetic will be required for the sizing of the giant A.

Just try. Evolve your solution. Share when you get stuck, and we shall help.
I am trying to help you, really, even if it doesn't always seem that way
Reply
#5
Hello!

Yes, I'm a green bean, a newbie trying to figure this stuff out I really appreciate everyone feedback this will definitely point me in the correct direction. I'm starting to understand but a very big beginner, however, I will continue until I know and understand better. Again, I appreciate your help with getting me to the correct page.

Thanks,
aka2d7
Reply
#6
Hi! I am having trouble with this same assignment. This is what I have so far and when I run it, it only displays the street number: 37

street_number1 = eval(input("37"))
street_name1 = input("Peak Lane")
city1 = input("Woodbridge")
state1 = input("Maryland")
zip1 = eval(input("21220"))

print ("Employee Info: ")
print ("street_number1 street_name1 , city1 state1 , zip1")
Reply
#7
The proper syntax of the input statement is that what is between quotes is usually a question and then you have to enter an answer on the keyboard, followed by the Enter key to validate your input. Example:
age = eval(input("What is your age? "))
Reply
#8
eval() is used to evaluated a string as if it were an expression - as anything can be entered by the user, you should be very careful and selective in use of this function.

Why are you doing evaluation anyway? If you simply want to convert a string of digits into a number you can do arithmetic on, then use int() or float() BUT in this case, why not just keep it as a string given one rarely needs to do sums on house numbers (and some properties do not have a house number anyway).

Regarding the output, everything inside a print() statement that is in quotes is output literally. If you want the value of a variable (instead of the literal name of the variable) output, you need to include each variable name inside the print() statement without surrounding quotations.

age = 20
name = "Fred"
print(name, age)
There are ways of formatting output that you can work on next.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020