Example HTML page

Python Exercise 9

Hi,

Do the following programs by using only ternary type in python.

1. Write a python script to read two integers from the user and print the sum of two numbers using ternary type construct?

2. Write a python script to read a three numbers from the user and print the maximum number using ternary type construct?

3. Write a python script to read a three numbers from the user and print the minimum number using ternary type construct?

4. Write a python script to read a ‘Alphabet character’ from the user and print the ASCII value of the corresponding character, if user entered more than two letters in the string print a message that ” please enter only one letter”.

5. Write a python script to read a number from the user and print the ASCII character of the corresponding number. if user entered more than 256, it should print a message that “please enter a number between 0 to 256”

6. Write a python script to read a character from the user, if user enters ‘M’ it should print you are male, if he enter ‘F’ it should print you are female. For any other characters, it should print a message that ” Please enter either ‘M’ or ‘F’. use only ternary operator.

7. Write a python script to read a string either ‘Sunny’ or ‘Cloudy’. If the user enter ‘Sunny’, then print ” I will go to shopping” else it should print “I will go tomorrow”.

8. Write a python script to read a number and check the number is even or odd. For example, if the number is 4, then it should print “Even”, otherwise “Odd”.

9. Write a python script to read a number and check the number is positive or negative. For example, if the number is -4, then it should print “negative”, otherwise “positive”.

10 Write a python script to read two integers and one operator from the user. If operator is “+” it should print sum, if the operator is  “*” it should print multiplication result of the two integers. For other cases, it should print ” please enter either “+” or “*” “

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest