Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help #58

Open
Aprialmay opened this issue Jul 27, 2024 · 1 comment
Open

Help #58

Aprialmay opened this issue Jul 27, 2024 · 1 comment

Comments

@Aprialmay
Copy link

I'm am programming beginner
I do not know what is the problem about my programs
https://tmc.mooc.fi/paste/P9pRaa6UaebbGClFGCCWUA

@Yellecode
Copy link

Yellecode commented Jul 28, 2024

Hello Aprialmay,

First of all, I am nowhere near the exprience of a teacher, but for this one I feel comfortable to provide some knowledge.
I think this exercise is broken at the moment. Whatever you submit even correctly, it fails.

That being said, it doesn't mean we cannot improve your code.

Your code:

given_name=input("given name:")
family_name=input("family name:")
street_address=input("street address:")
city=input("city:")
postal_code=input(" postal code:")
#Print the information in the specified format
print(f"\n{given_name Steve}{family_name Sanders}")
print(f"\n{street_address 91 Station Road}" )
print(f"\n{city London}{postal_code EC05 6AW}")

The prompts for user input are fine, but it's generally good practice to make them more readable by capitalizing the first letter and maintaining consistent spacing. For example, use "Given name: " instead of "given name:".

Incorrect Variable Usage in Print Statements:
The print statements are attempting to mix variables and hardcoded text incorrectly.

For example:

print(f"\n{given_name Steve}{family_name Sanders}")

This line attempts to concatenate the variable given_name directly with the text "Steve" and the variable family_name directly with "Sanders". This is not how variables and strings should be combined.

Hardcoded Values:
The provided print statements use hardcoded values (e.g., "Steve", "Sanders", "91 Station Road", "London", "EC05 6AW"). Instead, we should use the variables that store the user inputs.

Corrected Code:

# Ask for the user's name and address

given_name = input("Given name: ")
family_name = input("Family name: ")
street_address = input("Street address: ")
city = input("City: ")
postal_code = input("Postal code: ")

Print the information in the specified format

print(f"\nGiven name: {given_name}")
print(f"Family name: {family_name}")
print(f"Street address: {street_address}")
print(f"City and postal code: {city} {postal_code}")

# Final output as required

print()
print(f"{given_name} {family_name}")
print(f"{street_address}")
print(f"{city} {postal_code}")

We ask the user for their given name, family name, street address, city, and postal code, and store these inputs in variables:

given_name = input("Given name: ")
family_name = input("Family name: ")
street_address = input("Street address: ")
city = input("City: ")
postal_code = input("Postal code: ")

We correctly use f-strings to include the values of the variables in our output:

print(f"\nGiven name: {given_name}")
print(f"Family name: {family_name}")
print(f"Street address: {street_address}")
print(f"City and postal code: {city} {postal_code}")

We print the name and address in the final required format:

print()
print(f"{given_name} {family_name}")
print(f"{street_address}")
print(f"{city} {postal_code}")

Summary:
Input: We gather user input correctly.
Output: We use the variables to print the collected information in the specified format without hardcoding any values.
Formatting: We ensure that the prompts and outputs are formatted cleanly and consistently.

This approach ensures the program is flexible and correctly displays the user's input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants