Task 1: Write A Program To Demonstrate Different Number Data Types in Python
Task 1: Write A Program To Demonstrate Different Number Data Types in Python
Task 1: Write A Program To Demonstrate Different Number Data Types in Python
Code:
print(type(a))
print(type(b))
print(type(c))
#Output :
Task 2: Write a program to perform different Arithmetic Operations on
numbers in Python.
Code:
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
#Output:
Task 3: Write a program to create, concatenate and print a string and accessing
sub-string from a given string.
Code:
#Output:
Task 4: Write a python program to find largest of three numbers.
Code :
if a>b:
if a>c:
print ("A is greater.")
else:
print("C is Greater")
elif b>c:
print("B is greater")
else:
print ("C is greater")
#Output:
Task 5: Write a Python program to convert temperatures to and from Celsius,
Fahrenheit. [ Formula: c/5 = f-32/9]
Code:
if choice == 1:
f=int(input("Enter the temp in Fahrenheit"))
c=(5*(f-32))/9
print(f"Temp in Celcius is : {c}")
elif choice ==2:
c=int(input("Enter the temp in Celcius"))
f=(9*c)/5 + 32
print(f"Temp in Celcius is : {f}")
else:
print ("invalid choice")
#Output:
Fahrenheit to Celsius
Celsius to Fahrenheit
Task 6: Write a python script to print the current date in the following format
“Sun May 29 02:26:23 UTC 2017”
Code:
import time
ltime = time.localtime();
print(time.strftime("%a %b %d %H:%M:%S %Z %Y",ltime));
#Output:
Task 7: Write a Python program to construct the following pattern, using a
nested for loop
*
**
***
****
***
**
*
Code :
#Output:
Task 8 : Write a Python script that prints prime numbers less than 20.
Code:
if (prime==True):
print (num)
#Output:
Task 9: Write a program to demonstrate working with tuples in python.
Code:
My_tupple = ("a",)
my_tupple_1 = ("a","b","c","d","e","f")
my_tupple_2 = "Hello" , "Myname" , "cat","dog"
my_tupple_3 = ("Hello" , "Myname" , "cat","dog")
my_tupple_4 = (1,2,3,[4,5,6])
print (type(my_tupple))
print (type(my_tupple_1))
print (type(my_tupple_2))
print (type(my_tupple_3))
print (type(my_tupple_4))
print("\n")
print(my_tupple)
print(my_tupple_1)
print(my_tupple_2)
print(my_tupple_3)
print("\n")
print(my_tupple_2[3])
print(my_tupple_2[3][2])
print(my_tupple_1[-5])
print("\n")
my_tupple_4[3][1] = 9
print(my_tupple_4)
#output