New in python need help for program

-displays the phrase: what your continents
-read continent
-answer: the continent is:
“America” if “A” , “European” if “E” , “Asian” if “An”, Africa if “AF”

Thank you for your help
I need to create this easy program but i know how to do it

Hello, @Patoloco20, and welcome to Python Software Foundation Discourse!

Is this a homework assignment?

Please let us know what you have already learned about Python programming. Are you familiar with any of the following:

  • The input() function
  • The print() function
  • if - elif - else conditional statements
  • dictionaries
  • Creating and calling your own Python functions

We hope you enjoy the discussions here. For additional information about this forum, please see:

EDITED (November 30, 2022) to correct a typographical error.

Hi a little homework
Where is what i done

Continents =float (input ("what is your contient A,AF,AN,E ? : ")

AF = AFRICA
A = AMERICA
AN = ASIA
E= EUROPEAN

IF CONTINENTS == AF :
PRINT("THE CONTINENTS IS AFRICA ")

When you post Python code, please format it correctly for posting, so that essential details such as indentation, quote marks, and other features are displayed properly. One technique for accomplishing this is to place lines (fences) of three back ticks before and after the code, as follows:

```
# This is example code.
print("Hello, World!")
```

You also have the option of selecting the code and clicking the </> button at the top of the editing window.

Remember that Python is case-sensitive. For example, PRINT in the following will not work:

PRINT("THE CONTINENTS IS AFRICA ")

This will work:

print("THE CONTINENTS IS AFRICA")

However, this might produce output that looks better:

print("The continent is Africa.")

For this project, the user’s input should not be converted to a float. You are not dealing with numbers here. Your statement for collecting the input should be like this:

continent = input("what is your continent A,AF,AN,E ? : ")

Note that some spelling adjustments have been made in the above.

Remember that in Python, indentation is important. Please consider this example:

if country == "France":
    print("The capital is Paris.")

Please try to complete your code, then post it again, with proper formatting.

Python is case-sensitive: PRINT is not the same as print. One of them works, the other will give you an error. Can you work out which one is which?

When you set a variable to a string, like this:

AF = AFRICA

the string needs to be in quotation marks:

AF = "AFRICA"

Why are you converting the user’s continent into a float?

float(input("what is your contient A,AF,AN,E ? : ")

If the user types “AF”, Python will try to turn “AF” into a floating point number like 2.175 or 3.5, and fail with an error.

@Patoloco20, this won’t work in your program:

AF = AFRICA
A = AMERICA
AN = ASIA
E= EUROPEAN

In addition to the fact that literal strings need to be delimited by quotation marks, you don’t need to create a separate variable for each continent. If you do the following, the user’s input will be represented by the variable, continent, and that is the only variable that you will need:

continent = input("what is your continent A,AF,AN,E ? : ")

But let’s digress a little bit by offering an example below that resembles a solution that will work for you, but differs sufficiently from an actual solution to avoid our doing your homework for you, which would detract from your learning experience.

city = input("Name a city from my book (Paris or London): ")
if city == "Paris":
    print("I worked in France.")
elif city == "London":
    print("I worked in England.")
else:
    print(city + " is nice, but it wasn't in my book.")

print("Regards, Eric Arthur Blair")

In the above, the user enters the name of a city, and that input is checked in the conditional block headers. For your homework, you would be checking, instead, for the various abbreviations for continents that the user is expected to enter.

1 Like