Question

In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string dat...

In PYTHON ONLY PLEASE

You will use a dictionary in Python

You only have string in Python so you have to use a string data type

Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior.

Use character data type for c++. Then you can say something like:

char level ='f';

level=toupper(level);

You would need a loop for 1 to 5, to test for f, s, j, r and also anillegal grade level. Use a "z" for the illegal grade level

Convert the input to upper case so you won't have a case in your switch for both lower and upper case letters.

Remember, a switch statement is just another way of writing an if statement.

Then inside the switch statement print out if they were a freshman, sophomore, etc. spelled all the way out.

So the input for freshmen is a "f", but the output is "Freshmen".

Unlike most other programming languages I've used before, Python does not have a switch or case statement. To get around this fact, we use dictionary mapping.A later chapter in the Python book (14)covers dictionaries plus I have some examples in the daily lessons.

switcher = {

0: "zero",

1: "one",

2: "two",

}

return switcher.get(argument, "nothing")

Another Python Example:

states={

'AL':"Alabama",

'GA':"Georgia",

"FL":"Florida"

}

You can use single or double quotes in Python

So you have an outer loop from 1 to 5, then inside the loop

you enter a letter

change the letter to upper case

have a switch statement or dictionary to check what was entered from the keyboard and print the appropriate grade level spelled out as in "Senior".

Use the appropriate syntax for your programming language. C++ and Java are almost the same. Don't forget your breaks in the switch statement.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

grades { 1 Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux Enter a letter: F F: freshman, s: sophomore

grades = {
        'F': 'freshman',
        'S': 'sophomore',
        'J': 'junior',
        'R': 'senior'
}

for i in range(5):
        c = input('Enter a letter: ')[:1]
        c = c.upper()

        if c in grades:
                print('you are', grades[c])
        else:
                print('Invalid grade character.')

please upvote.. answered in python.

Add a comment
Know the answer?
Add Answer to:
In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string dat...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in th...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the...

  • IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse,...

    IN PYTHON ONLY I am looking for 4 columns, Age, Gender, Ideal Age of a Spouse, and the message. I will have 6 rows in the table, and 4 columns, followed by  averages. Calculate the ideal age of a spouse. Enter either m or f from the keyboard in lower case. You may use string data for the gender. Convert the gender to upper case Enter an age from the keyboard, probably an integer You will need prompts telling the user...

  • Could use some help with this, Instructions: You will need to add an input statement for...

    Could use some help with this, Instructions: You will need to add an input statement for the grade variable to this code. Also add a for loop so that you can enter more than one grade. Code the for loop so that at least 7 grades can be entered. #include <iostream> #include <string> using namespace std; void main() {      char grade;           for (int x = 0; x < 7; x++)      {            cout << "Enter a...

  • PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do...

    PYTHON PROGRAMMING Instructions: You are responsible for writing a program that allows a user to do one of five things at a time: 1. Add students to database. • There should be no duplicate students. If student already exists, do not add the data again; print a message informing student already exists in database. • Enter name, age, and address. 2. Search for students in the database by name. • User enters student name to search • Show student name,...

  • Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/...

    Write a Python equivalent program for the Unix spell utility. You can use the dictionary at /usr/share/dict/words (if you machine does not have it, you can copy it from a Linux machine such as npu29). The minimum requirement is to check if each word in the file exists in the dictionary as is (case insensitive). Your spell checker should inlcude at least two features: 1. Check the simple plural forms (add s or es). 2. Check the simple verb past...

  • s1 = 'Practice How to Use String Object' Write a python statement that splits the string,...

    s1 = 'Practice How to Use String Object' Write a python statement that splits the string, creating the following list: ['Practice', 'How', 'to', 'Use', 'String', 'Object'] 2. Assume reply references a string. The following if statement determines whether reply is equal to ‘Y’ or ‘y’: reply = input("Y or y to continue: ") if reply == "Y" and reply == "y":    print("Y --- <uppercase> has been selected. ") else:    print("y --- <lowercase> has been chosen. ") print("… continue...

  • Can I have the code in Python and the output 2-3-B for GPA You previously calculated...

    Can I have the code in Python and the output 2-3-B for GPA You previously calculated a GPA using a loop; in this assignment you'll use a for loop A GPA, or Grade Point Average, is calculated by summing the grade points earned in a student's courses and then dividing by the total units The grade-points for an individual course are calculated by multiplying the units for that course by the appropriate factor depending upon the grade received A receives...

  • Please complete the following: Write a Python script to do the following: 1. Ask the use...

    Please complete the following: Write a Python script to do the following: 1. Ask the use to enter several sentences, one at a time in a loop). To end the sentence entry, the user enters a blank (empty) sentence. 2. Extract each word from each sentence and put it in a list. This will require at least one loop to go through each sentence in the list. It is up to you how you want to get the words in...

  • Please do the following project in C++ programming language. You can use a bag to create...

    Please do the following project in C++ programming language. You can use a bag to create a spell checker. The bag serves as a dictionary and contains a collection of correctly of correctly spelled workds. To see whether a word is spelled correctly, you see whether it is contained in the dictionary. Use this scheme to create a spell checker for the words in an external file. To simplify your task, restrict your dictionary to a manageable size. The dictionary...

  • Question: Case Study Baseball Team Manager For this case study, you’ll use the programming skills that...

    Question: Case Study Baseball Team Manager For this case study, you’ll use the programming skills that you ... Case Study Baseball Team Manager For this case study, you'll use the programming skills that you learn in Murach s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game After you read chapter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT