(a) Give an example for each of the following Python language constructs: i. Exp
ID: 3761411 • Letter: #
Question
(a) Give an example for each of the following Python language constructs: i. Expression ii. Assignment Statement iii. Conditional Expression (b) What is the value of the following expressions? i.1/2 ii. 20 - 4 * 8 + 2 (c) Write Python code that declares and initialises three variables num 1, num 2 and, name with initial values 98, -32 and Simon respectively. The program should then declare a fourth variable sum, and assign the sum of num 1 and num 2 to the variable sum. Lastly, the values of num 1 and sum should be displayed.Explanation / Answer
Give an example of:
i. Expression. 2+3*4
ii. Assignment Statment. variable = 2+3*4;
iii. Conditional Expression.
if(variable < 10):
print variable;
else:
print "Oops.";
What is the value of the following expressions:
i. 1/2 0
ii. 20 - 4 * 8 + 2 -10
Code for your requirement.
num1 = 98; #initialize num1 to 98.
num2 = -32; #initialize num2 to -32.
name = "Simon"; #initialize name to Simon.
sum = num1 + num2; #assign num1 + num2 to sum.
print "num1: ", num1; #display num1 value.
print "sum : ", sum; #display sum value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.