Computer Science, asked by aishwaryasingh7722, 5 months ago

write a pythong program which assigns values to four variable and show their addition (class9 level)​

Answers

Answered by allysia
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