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

ECE054-Lab2

The document contains a series of Python code snippets and their outputs, demonstrating various programming concepts such as arithmetic operations, conditional statements, and user input handling. It includes examples of calculating areas, swapping values, and simple interest, along with formatted print statements. The code is designed for educational purposes, likely as part of a lab exercise for a programming course.

Uploaded by

cocifis518
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ECE054-Lab2

The document contains a series of Python code snippets and their outputs, demonstrating various programming concepts such as arithmetic operations, conditional statements, and user input handling. It includes examples of calculating areas, swapping values, and simple interest, along with formatted print statements. The code is designed for educational purposes, likely as part of a lab exercise for a programming course.

Uploaded by

cocifis518
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

28/10/2023, 14:38 ECE054-Lab2.

ipynb - Colaboratory

2+8/2*3

14.0

(6+3)-8//4*2+3

2+8//2+3

2**(2+3)-4/2*2+2

30.0

5<6<8

account_circle True

5*3> 10 and 4+6==11

False

x = 4
print("ABC"*x)

ABCABCABCABC

print(int(2**3/5))

x,y = 7,2
x,y,x = x+1,y+3,x+10
print(x,y)

17 5

name = "Krishna"
age = 21
print("Hello", name, "Your age is", age, end="")

Hello Krishna Your age is 21

name = "Krishna"
age = 21
print("Hello", name, "Your age is", age, end="")
print(" You will be",age+1, "next year")

Hello Krishna Your age is 21 You will be 22 next year

name = "Krishna"
age = 21
print("Hello", name, "Your age is", age, end="/n")
print(" You will be",age+1, "next year")

Hello Krishna Your age is 21/n You will be 22 next year

name = "Krishna"
age = 21
print("Hello", name, "Your age is", age, )
print(" You will be",age+1, "next year")

Hello Krishna Your age is 21


You will be 22 next year

x**1/2

8.5

https://colab.research.google.com/drive/1O30QT2xoPmWk4SAHWSsSWvHsONixdEve#printMode=true 1/4
28/10/2023, 14:38 ECE054-Lab2.ipynb - Colaboratory
b= 2
h = 3
print(0.5*b*h**2)

9.0

x = 2
print(x**1/2)

1.0

x = 4
print(x**1/2)

2.0

x = 13
print(x**0.5)

3.605551275463989

a= 3.14
b= int(input("Enter radius "))
c = 2*a*b
print("Circumference =",c)

Enter radius 2
Circumference = 12.56

a= 3.14
b= int(input("Enter radius "))
c = a*b**2
print("Area =",c)

Enter radius 2
Area = 12.56

x1 = int(input(" Enter x1 :"))


x2 = int(input(" Enter x2 :"))
y1 = int(input(" Enter y1 :"))
y2 = int(input(" Enter y2 :"))
print((((x2-x1)+(y2-y1))**2)**0.5)

Enter x1 :1
Enter x2 :1
Enter y1 :1
Enter y2 :1
0.0

b = 5
a = 1
c = 1
-b+((b**2-4*a*c)**0.5)/(2*a)

-2.70871215252208

q = int(input(" Enter a value for q:"))


Q = int(input(" Enter a value for Q :"))
print( "Sum is",q+Q, )

q = input(" Enter a value for q :")


Q = input("Enter value for Q :")
x = int(q)
y = int(Q)
z = x+y
print(z)

a = input(" Enter your name")


b = int(input(" Enter your age:"))
c = float(input(" Enter your marks:"))
print(" The name is:",a)
print(" The age is:",b)
print(" The marks is:",c)

https://colab.research.google.com/drive/1O30QT2xoPmWk4SAHWSsSWvHsONixdEve#printMode=true 2/4
28/10/2023, 14:38 ECE054-Lab2.ipynb - Colaboratory

Enter your name Hari


Enter your age: 18
Enter your marks: 97
The name is: Hari
The age is: 18
The marks is: 97.0

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

a= input("Enter a value :")


b = int(a)
print(b+1)

Enter a value : 3
4

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.

a = int(input(" Enter the first number :"))


b = int(input(" Enter the second number :"))
c = int(input(" Enter the third number :"))
d = int(input(" Enter the fourth number :"))
e = int(input(" Enter the fifth number :"))
x = a+b+c+d+e
print(" The sum of entered numbers is :", x)

Enter the first number : 10


Enter the second number : 20
Enter the third number : 30
Enter the fourth number : 40
Enter the fifth number : 50
The sum of entered numbers is : 150

Write the code that accepts five values from the user and displays the concatenated result of all the five values

a = input(" Enter the first number :")


b = input(" Enter the second number :")
c = input(" Enter the third number :")
d = input(" Enter the fourth number :")
e = input(" Enter the fifth number :")
x = a+b+c+d+e
print(" The concatenated result of all the five values is :", x)

Enter the first number : 10


Enter the second number : 20
Enter the third number : 30
Enter the fourth number : 40
Enter the fifth number : 50
The concatenated result of all the five values is : 1020304050

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

x = int(input(" Enter the first number :"))


y = int(input(" Enter the second number :"))
k = x
x = y
y = k
print(" The values after swapping are",x," and",y,"respectively")

Enter the first number : 12


Enter the second number : 34
The values after swapping are 34 and 12 respectively

Write a program to calculate the area of an equilateral triangle if the length of a side is given by the user.

x = int(input(" Enter the first number :"))


y = int(input(" Enter the second number :"))
x,y = y,x
print(" The values after swapping are",x," and",y,"respectively")

Enter the first number : 100


Enter the second number : 1200
The values after swapping are 1200 and 100 respectively

https://colab.research.google.com/drive/1O30QT2xoPmWk4SAHWSsSWvHsONixdEve#printMode=true 3/4
28/10/2023, 14:38 ECE054-Lab2.ipynb - Colaboratory

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

a= int(input(" Enter the time in seconds :"))


b = a//3600
a = a%3600
c = a//60
a = a%60
print(" The time will be ",b,"hour",c,"minutes",a,"seconds")

Enter the time in seconds : 3700


The time will be 1 hour 1 minutes 40 seconds

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.

print(" Froggy's jump")


k = int(input(" Enter how many jumps the frog completed :"))
a = k*5
print(" The position of the frog will be at the ",a,"th unit on x axis")

Froggy's jump
Enter how many jumps the frog completed : 2
The position of the frog will be at the 10 th unit on x axis

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 4 to the right, and the fourth jump is b units to the left, and so on. Your task is to calculate the position of the frog
after k jumps. Inputs - a, b, and k.

a = int(input(" Enter the jumping units to right :"))


b = int(input(" Enter the jumping units to left :"))
k = int(input(" Enter the number of jumps :"))
x = k*a - k*b
print(" The position of the frog is at", x , "position")

Write a program to calculate simple interest

p= int(input(" Enter the principal amount :"))


r = int(input(" Enter the rate :"))
t = int(input(" Enter the time (in years)"))
s = p*r*t/100
print(" Simple interest is ",s)

Enter the principal amount : 2000


Enter the rate : 40
Enter the time (in years) 2
Simple interest is 1600.0

https://colab.research.google.com/drive/1O30QT2xoPmWk4SAHWSsSWvHsONixdEve#printMode=true 4/4

You might also like