Question

In Python only. Write a program that prompts the user to enter a hex character and...

In Python only. Write a program that prompts the user to enter a hex character and displays its corresponding decimal integer.

Homework Answers

Answer #1

Python code:

#accepting input
hex_num=input()
#checking if it is a number
if(hex_num>='0' and hex_num<='9'):
    #printing that number
    print(hex_num)
#checking if it is a or A
elif(hex_num=='a' or hex_num=='A'):
    #printing its corresponding number
    print(10)
#checking if it is b or B
elif(hex_num=='b' or hex_num=='B'):
    #printing its corresponding number
    print(11)
#checking if it is c or C
elif(hex_num=='c' or hex_num=='C'):
    #printing its corresponding number
    print(12)
#checking if it is d or D
elif(hex_num=='d' or hex_num=='D'):
    #printing its corresponding number
    print(13)
#checking if it is e or E
elif(hex_num=='e' or hex_num=='E'):
    #printing its corresponding number
    print(14)
#checking if it is f or F
elif(hex_num=='f' or hex_num=='F'):
    #printing its corresponding number
    print(15)


Screenshot:


Input and Output:

Know the answer?
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
Similar Questions
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Write a complete program that prompts the user to enter the number of students and each...
Write a complete program that prompts the user to enter the number of students and each student’s score, then finally displays the highest score.(in C++)
(Python Programming) Write a program that prompts a user for a positive integer and then uses...
(Python Programming) Write a program that prompts a user for a positive integer and then uses a loop to calculate and display the sum of specific fractions as follows: Let's say the user enters 5, then your program will compute: 1/5 + 2/4 + 3/3 + 4/2 + 5/1 which is 8.7.
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
Modify the program so that it prompts the user to enter an entire line, reads the...
Modify the program so that it prompts the user to enter an entire line, reads the line, then echoes the entire line. Read only one byte at a time from the keyboard.Explain what you did. #include int main(void) { char aLetter; write(STDOUT_FILENO, "Enter one character: ", 21); // prompt user read(STDIN_FILENO, &aLetter, 1); // one character write(STDOUT_FILENO, "You entered: ", 13); // message write(STDOUT_FILENO, &aLetter, 1); // echo character return 0; }
Write a program In python of Jupiter notebook That prompts the user to enter his/her first...
Write a program In python of Jupiter notebook That prompts the user to enter his/her first name, last name, and year of birth in a single string (in the format: fn;ln;yyyy), then calculates the age tell it to him/her after greeting him/her using the first name. Make sure to capitalize the user's first name, regardless of how he/she typed it in. Hint: review Exercise 1! Example: Enter your first name, last name, and birth year (in format fn;ln;yyyy): alex;smith;1994 Hi...
Write a program that prompts the user to enter the currency exchange between US dollars and...
Write a program that prompts the user to enter the currency exchange between US dollars and the Chinese renminbi. prompt the user to enter 0 to convert from us dollars to Chinese RMB and 1 for vice versa. Prompt the user to enter the amount in US dollars or Chinese RMB to convert it to Chinese RMB or US dollars, respectively, Sample Run: Enter the exchange rate from dollars to RMB: 6.58 Enter 0 to convert dollars to RMB and...
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last...
Python Jupyter Notebook Write a program that prompts the user to enter his/her first name, last name, and year of birth in a single string (in the format: fn;ln;yyyy), then calculates the age tell it to him/her after greeting him/her using the first name. Make sure to capitalize the user's first name, regardless of how he/she typed it in. Hint: review Exercise 1! Example: Enter your first name, last name, and birth year (in format fn;ln;yyyy): alex;smith;1994 Hi Alex, you...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT