write a pythong program which assigns values to four variable and show their addition (class9 level)
Answers
Answered by
7
Language:
Python
Method 1:
Programmer defined:
Program:
a,b,c,d = 1,2,3,4
print(a+b+c+d)
Through user input:
Program:
a,b,c,d = int(input("Enter 1st number: ")), int(input("Enter 2nd number: ")), int(input("Enter 3rd number: ")), int(input("Enter 4thnumber: "))
print(a+b+c+d)
Method 2:
Programmer defined:
Program:
a=1
b=2
c=3
d =4
print(a+b+c+d)
Through user input:
Program:
a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
c = int(input("Enter 3rd number: "))
d = int(input("Enter 4thnumber: "))
print(a+b+c+d)
Explanation:
- input() : Takes user input and accepts input statement as argument.
- int() : converts a datatype to integer if possible else reports error.
Similar questions
Environmental Sciences,
2 months ago
English,
2 months ago
Math,
5 months ago
English,
11 months ago
Social Sciences,
11 months ago
Biology,
11 months ago