0% found this document useful (0 votes)
2K views10 pages

Task 1: Write A Program To Demonstrate Different Number Data Types in Python

The document contains 9 tasks that demonstrate different Python programming concepts. Task 1 shows how to define integer, float, and complex number data types. Task 2 demonstrates arithmetic operations. Task 3 covers string operations like concatenation and slicing. Task 4 finds the largest of three numbers. Task 5 converts between Celsius and Fahrenheit temperatures. Task 6 prints the current date and time. Task 7 constructs a pattern using nested loops. Task 8 prints prime numbers less than 20. Task 9 works with tuples, including indexing, slicing, and modifying elements.

Uploaded by

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

Task 1: Write A Program To Demonstrate Different Number Data Types in Python

The document contains 9 tasks that demonstrate different Python programming concepts. Task 1 shows how to define integer, float, and complex number data types. Task 2 demonstrates arithmetic operations. Task 3 covers string operations like concatenation and slicing. Task 4 finds the largest of three numbers. Task 5 converts between Celsius and Fahrenheit temperatures. Task 6 prints the current date and time. Task 7 constructs a pattern using nested loops. Task 8 prints prime numbers less than 20. Task 9 works with tuples, including indexing, slicing, and modifying elements.

Uploaded by

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

Task 1: Write a program to demonstrate different number data types in Python.

Code:

a=int(input("Enter the value of Integer A : "))


b=float(input("Enter the Value of B in float : "))
c=complex(input("Enter the value of Complex no. C : "))

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:

a=int(input("Enter the value of A: "))


b=int(input("Enter the value of B: "))

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:

a = input("Enter the String A: ")


b = input("Enter the String B: ")
c = a + b
print (c)
print(c[:3])

#Output:
Task 4: Write a python program to find largest of three numbers.

Code :

a=int(input("Enter the value of A: "))


b=int(input("Enter the value of B: "))
c=int(input("Enter the value of C: "))

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:

choice= int(input("To convert Temperature to Celcius, Press


1 or To convert Temperature to Fahrenheit, Press 2"))

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 :

n=int(input("Enter the value of range: "))


for i in range(n):
for j in range(i):
print("*",end="")
print("\n")
for i in range(n,0,-1):
for j in range(i):
print("*",end="")
print("\n")

#Output:
Task 8 : Write a Python script that prints prime numbers less than 20.

Code:

for num in range(2,20):


prime = True
for i in range (2,num):
if(num % i ==0):
prime = False

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

You might also like