0% found this document useful (0 votes)
20 views

Lab 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lab 2

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Computational Problem Solving

Lab sheet 2

Academic Year: 2023-2024

Give proper comments in your jupyter notebook by selecting the markdown option.
Answers to Lab sheets to be submitted before the due date. Download the PDF and .ipynb
version of the jupyter notebook and submit in AUMS.
The lab sheet should be named CSE080-Lab-1.pdf (if your roll number is AM.EN.U4CSE23080)

Questions

1. For the following questions, first you predict the output of the given expressions
and then execute the expression in notebook and see whether the prediction was
correct or not. If the prediction was wrong, find the reason.

a) 2 + 8/2 ∗ 3
(b) 2 + 8//2 ∗ ∗3
(c) (6 + 3) − 8//4 ∗ 2 + 3
(d) 2 ∗ ∗(2 + 3) − 4//2 ∗ 2 + 2
(e) 5<6<8
(f) 5*3 > 10 and 4+6==11
(g) x=4
print(”ABC”*x)
(h) print(int(2**3 /5))
(i) x,y=7,2
x,y,x = x+1, y+3, x+10 print(x,y)

(j) name = ”Krishna” age = 21

print(”Hello”, name, ”Your age is ”, age, end=””)


print(”You will be”, age+1, ”Next year”)
(k) name = ”Krishna” age = 21

print(”Hello”, name, ”Your age is ”, age)


print(”You will be”, age+1, ”Next year”)
2. Write the following mathematical expression in python

1
3. Accepting user input. Write your observations of the output of (a) to (d)
(a)

(b)

(c)

(d)

2
4. If the number 3 is entered by the user when the following code is run,
what should be written in the missing part for the output to be 4

5. Write the code that accepts five values from the user and displays the sum of
all the five values. For eg: if the user enters 10, 20, 30, 40 and 50 are the
values, the output should be 150.
6. Write the code that accepts five values from the user and displays the
concatenated result of all the five values. For eg: if the user enters 10, 20, 30,
40 and 50 are the values,the output should be 1020304050

7. Write a program to calculate the area of a circle, for a radius given by the
user. Give a proper formatted output.

8. Write a program to calculate the area of an equilateral triangle if the length of a


side is given by the user.

9. Write a program to calculate simple interest.

10. Write a program to read the number of seconds and print it in the form
hr:min:sec.

11. Can you write the code to swap the values of two variables
(i) Using a third variable
(ii) Without using a third variable

12. A frog is currently at point 0 on x − axis. It jumps by the following way: It always
jumps to the right by a units. Your task is to calculate the position of the frog after
k jumps. Inputs - a and k. See the following figure

13. A frog is currently at point 0 on x − axis. It jumps by the following way: the first jump
is a units to the right, the second jump is b units to the left, the third jump is a units
to the right, and the fourth jump is b units to the left, and so on. Your task is to calculate
3
the position of the frog after k jumps. Inputs - a, b, and k. See the following figure.

4
5
name = input("Enter your name: ") # String Input
age = int(input("Enter your age: "))# Integer Input
marks = float(input("Enter your marks: ")) # Float Input
print("The name is:", name)
print("The age is:", age)
print("The marks is:", marks)

You might also like