Practice questions for user input & type conversion

There are three simple questions with the source code to help you understand more about accepting user input and type conversion. If you still face problems understanding the user input concept, you may find this article helpful. Click here.

Question 1:

Write a program to display the mark of a student. You should get the student’s name, marks obtained in Dzongkha, English, and Mathematics from the user. Finally, display the result. The sample output is attached below.

Source code:

name = input("Your name:")
dzo = int(input("Marks in Dzongkha:"))
eng = int(input("Marks in English:"))
math = int(input("Marks in Mathematics:"))
print("Name:", name)
print("Dzongkha:", dzo)
print("English:", eng)
print("Mathmatics:", math)


Your name:Sonam Dorji
Marks in Dzongkha:98
Marks in English:88
Marks in Mathematics:100
Name: Sonam Dorji
Dzongkha: 98
English: 88
Mathmatics: 100

Question 2:

Write a program that accepts data from a user. Your program should accept your name, age, and height. A name should be a string, age should be an integer and the height should be float.

Source code:

name = str(input("Your name:"))
age = int(input("Your age:"))
height = float(input("Your height:"))

print("\nHello ", name)
print("You are", age, "years old.")
print("And you are ", height, "feet tall.")


Your name:Sonam
Your age:27
Your height:5.7

Hello  Sonam
You are 27 years old.
And you are  5.7 feet tall.

Question 3:

Write a program that accepts your name and five subjects mark. Print an output where you will see your name and five subjects mark including your average mark.

Source code:

name = input("Enter your name:")
eng = float(input("Enter English mark:"))
dzo = float(input("Enter Dzongkha mark:"))
math = float(input("Enter Math mark:"))
sci = float(input("Enter Science mark:"))
ict = float(input("Enter ICT mark:"))

total_mark = eng + dzo + math + sci + ict
average = total_mark/5

print("\n----------Printing result-----------\n")
print("Name:", name)
print("English Mark:", eng)
print("Dzongkha Mark:", dzo)
print("Math Mark:", math)
print("Science Mark:", sci)
print("ICT Mark:", ict)
print("Average:", average)


Enter your name:Pema
Enter English mark:45
Enter Dzongkha mark:67
Enter Math mark:66
Enter Science mark:78
Enter ICT mark:67

----------Printing result-----------

Name: Pema
English Mark: 45.0
Dzongkha Mark: 67.0
Math Mark: 66.0
Science Mark: 78.0
ICT Mark: 67.0
Average: 64.6