Lab-1 Questions and Solutions
Lab-1 Questions and Solutions
1. Raghav has been given the challenge to write a python program to add 5 and 7. How can
he do so?
Code: print(5+7)
2.Vigyan was asked to print the following using the print function. Help him in writing a
python program for the same. (The Golden Ratio has the same letters as The God
Relation.)
Code:print ("The Golden Ratio has the same letters as The God Relation.")
3.Indentation refers to the spaces at the beginning of a code line. Whereas in other
programming languages the indentation in code is for readability only, the indentation in
Python is very important.
When the following code is run, it gives an IndentationError which is a compile-time error.
Fix the code below and produce the intended output
i=4
j=3
if (i>j):
print(i)
Code:i = 4
j=3
if (i > j):
print(i)
4.Mohit is a very naughty child, when his brother was away from his laptop, he changed
his original program to the following:
x = input()
y = input()
if x>y:
else:
This program does not throw an error when it is run, rather it throws an error during
runtime. These kinds of errors are known as runtime errors.
If we give x=1, and y=2, the program runs fine, but when we give x=2 and y=1, the program
will throw an error.
Correct this code so that it is error-free.
Code:x = input()
y = input()
if x > y:
print("x is greater than y")
else:
print("y is greater than x")
5.Vishal was designing the front page of a website and he wrote the following code to
display a message to the user when he visits the website.
Correct Vishal’s code as the deadline is near and he is not able to solve the problem.
Code:
6.A friend told Dev that he can use the Python prompt to do some basic arithmetic
operations without using the input and output functions. Explain how he will perform the
operation 50 + 40 -35 in python.
Code: print(50+40-35)
CSET101-2023-Lab01-Tuesday
1.Smita does not know about the input and output functions in Python. How will she
multiply 12 by 10 and display the output?
Code:print(12*10)
2.Misha wants to create a script file in Python by the name of Misha.py which prints (My
name is Misha.). Help her to do so using the print() function with double quotes.
3.Your teacher has edited the correct program to test your knowledge. Now when you run
the following code, it gives a compile-time error. Fix this error and output the correct
string.
4.Amaan and Ayaan were given x and y apples respectively and then they were asked to
write a python program that would input x and y and display how many apples each
person had. You must write such a program.
Code:x = input()
y = input()
print("Amaan has",x,"apples.")
print("Ayaan has",y,"apples.")
5.Kushal is new to python programming and he was experimenting with the python
multiple assignment features. He wrote a program that would take in and assign 3
variables to 3 values in only 1 line of code. But while printing the values, he made an
error. Can you find and fix the error?
Code:a,b,c = 2,8,9
print (a,b,c)
c,b,a = a,b,c
print (a,b,c)
6.Kabir bought 20 mangoes and 23 oranges from a shop. Store these values in variables a
and b in a program and using print function display their respective values.
Code:a = 20
b = 23
print(a,b)
Code:a,b,c = 10,20,30
p,q,r = c-5,a+3,b-4
print ('a,b,c:', a,b,c, end ='')
print('p,q,r:',p,q,r)
CSET101-2023-Lab01-Wednesday
1.A friend told Dev that he can use the Python prompt to do some basic arithmetic
operations without using the input and output functions. Explain how he will perform the
operation 50 + 40 -35 in python.
Code:print(50+40-35)
2. Karan runs a restaurant and he wants to calculate price of 1 steak and 1 ratatouille
which cost x and y respectively, input x and y from the user and display total cost
customer has to pay.
Code:x = int(input())
y = int(input())
ans = x+y
print(ans)
3.As a software engineer in a good MNC, you must make students understand the
importance of mathematics in computer science (which is often overlooked). Do so by
creating a fun program.
Write a python program to display the following string and store the file as Mathisfun.py.
Math is Fun so don't be resistant. Just learn the rules,the rules are consistent. And most
important,you must be persistent.
Code: print("Math is Fun so don't be resistant. Just learn the rules,the rules are
consistent. And most important,you must be persistent.")
4.Kshitij runs a car dealership and he wanted to display the cost of 4 cars which he had
sold in the past week so he wrote the code given in the editor.
Your task is to identify the problem with this code and fix it to print the prices of the cars
(each in a new line)
code:x = input()
y = input()
a = input()
b = input()
print(x+"\n"+y+"\n"+a+"\n"+b)
code:age = 21
print ("You can vote")
7.Kabir bought 20 mangoes and 23 oranges from a shop. Store these values in variables a
and b in a program and using print function display their respective values.
Code:a = 20
b = 23
print(a,b)
CSET101-2023-Lab01-Thursday
Q1. You have been a software engineer for a decade and are used to writing programs in
python2.x. So, to print the string “Hello, World”, you wrote the following program:
Fix the code given above and print the string “Hello, World”.
Code
Q2. When writing a command line program for an assignment, Mr. Bruce Wayne wants to
write a program that prompts the user to input values for variables a and b, takes input,
and then displays the data. Can you help him in writing such a program?
Code
Q3. Vishal was designing the front page of a website and he wrote the following code to
display a message to the user when he visits the website.
name = input("What is your name?")
print ('Hi', name, ',')
print("How are you doing?")
Hi<name> ,
Correct Vishal’s code as the deadline is near and he is not able to solve the problem.
Code
Code
a = b = 0;
if(a == b):
c=a+b
print(c)
Code
Q6. Rishank bought 30 apples and 23 oranges from a shop. Store these values in variables
a and b in a program and using print function display their respective values.
Code
a = 30
b = 23
print(a,b)
Code
a,b,c = 10,20,30
p,q,r = c-5,a+3,b-4
print ('a,b,c:', a,b,c, end ='')
print('p,q,r:',p,q,r)
CSET101-2023-Lab01-Friday
Q1 . Nimish wrote the following code which gives a compile-time error. His teacher gave
him a hint that this error was caused because of some indentation problem. Your task is
to find that problem and fix it to produce the correct result.
Code
i=4
j=3
if (i>j):
print(i)
Q2 . Gautam wants to write a program in Python which asks for the values of d and e from
the user and then displays their values. Write a program to get input values for variables d
and e from the user and display the data.
Code
Q3. Vedant writes a program to ask the number of boys and girls in the class from the
user and then display their values. What is the code Vedant would have written using the
input and print functions.
Code
Q4. Rewrite the following code after removing all syntax errors:
Code
Code
a,b,c = 10,20,30
p,q,r = c-5,a+3,b-4
print ('a,b,c:', a,b,c, end ='')
print('p,q,r:',p,q,r)
Q7. Rivansh runs a restaurant and he wants to calculate price of 1 apple pie and 1
brownie which cost x and y respectively, take input x and y from the user and display
total cost customer has to paid.
Code
x = int(input())
y = int(input())
ans = x + y
print(ans)