Online Compiler

                Never    
7. Write a Python script that prints prime numbers less than 20.
Aim: To implement python program that prints prime numbers less than 20
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
r=int(input("Enter upper limit number:"))
for a in range(2,r):
 k=0
 for i in range(2,a//2+1):
 if(a%i==0):
 k=k+1
 if(k<=0):
 print(a)
Output:
Enter upper limit number:20
2
3
5
7
11
13
17
19



###########################

6. Write a Python program to convert temperatures to and from Celsius, Fahrenheit.
Aim: To implement python program to cover temperatures to and from Celsius, Fahrenheit
Description: C = (5/9) * (F - 32)
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
temp = input("Input the temperature you like to convert? (e.g., 45F, 102C etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]
if i_convention.upper() == "C":
 result = int(round((9 * degree) / 5 + 32))
 o_convention = "Fahrenheit"
elif i_convention.upper() == "F":
 result = int(round((degree - 32) * 5 / 9))
 o_convention = "Celsius"
else:
 print("Input proper convention.")
 quit()
print("The temperature in", o_convention, "is", result, "degrees.")
Output:
Input the temperature you like to convert? (e.g., 45F, 102C etc.) : 105F
The temperature in Celsius is 41 degrees.



#####£#############

5. Write a python program to find largest of three numbers.
Aim: To implement python program for finding largest of three numbers.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
num1=int(input("Enter numner1:"))
num2=int(input("Enter numner2:"))
num3=int(input("Enter numner3:"))
if num1>=num2 and num1>=num3:
 largest=num1
elif num2>=num1 and num2>=num3:
 largest=num2
else:
 largest=num3
print("Largest number between", num1,num2,"and",num3,"is", largest)
Output:
Enter numner1:12 
Enter numner2:10 
Enter numner3:5 
Largest number between 12 10 and 5 is 12





###########

5. Write a python program to find largest of three numbers.
Aim: To implement python program for finding largest of three numbers.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
num1=int(input("Enter numner1:"))
num2=int(input("Enter numner2:"))
num3=int(input("Enter numner3:"))
if num1>=num2 and num1>=num3:
 largest=num1
elif num2>=num1 and num2>=num3:
 largest=num2
else:
 largest=num3
print("Largest number between", num1,num2,"and",num3,"is", largest)
Output:
Enter numner1:12 
Enter numner2:10 
Enter numner3:5 
Largest number between 12 10 and 5 is 12



##################

4. Write a program to create, append, and remove lists in python.
.
Aim: To implement List data structure in python program.
Description:
A list is a collection which is ordered and changeable. In Python lists are written with 
square brackets.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:1
list1=[]
type(list1)
list1
list1.append(10)
list1.append(20)
list1.append(‘a’)
list1.append(‘b’)
list1.append(‘guru’)
list1.append(‘nanak’)
list1
list1.remove(10)
list1.remove(b)
Program:2
list1=[1,2,'q']
print(“Initial List:”,list1)
choice=1
while choice!=0:
 print("Exit-0,Append-1,Remove-2,Display-3")
 choice=int(input("Enter Your Choice:"))
 if choice==1:
 n=int(input("Enter Elemnt to Append:"))
 list1.append(n)
 print(list1)
 elif choice==2:
 n=int(input("Enter Element to remove:"))
 list1.remove(n)
 print(list1)
 elif choice==0:
 print("Exit") 
 else:
 print("Invalid")
Output:
[1, 2, 'q'] Exit-0,Append-1,Remove-2,Display-3 
Enter Your Choice:1 
Enter Elemnt to Append:10 
[1, 2, 'q', 10] Exit-0,Append-1,Remove-2,Display-3 
Enter Your Choice:2 Enter Element to remove:10 
[1, 2, 'q']



################

3. Write a program to create, concatenate and print a string and accessing sub-string from 
 a given string.
Aim: To implement python program for String operations such create string, concatenate strings 
 and access sub-string from a given string.
Description:
In Python, Strings are arrays of bytes representing Unicode characters. However, Python 
does not have a character data type, a single character is simply a string with a length of 
1. Square brackets can be used to access elements of the string
Creating a String:Strings in Python can be created using single quotes or double quotes or even 
 triple quotes.
Concatenate of Strings: String concatenation means add strings together.Use the + character to 
 add a variable to another variable:
Accessing characters in Python:
In Python, individual characters of a String can be accessed by using the method of 
Indexing. Indexing allows negative address references to access characters from the back 
of the String, e.g. -1 refers to the last character, -2 refers to the second last character and 
so on.
While accessing an index out of the range will cause an IndexError. Only Integers are 
allowed to be passed as an index, float or other types will cause a TypeError.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
String1= “Guru”;
String2= “Nanak”;
newstring= string1+string2;
print(“String1 is:” string1)
print(“String2 is”,string2)
Print(“Concatenation of two strings is”,newstring)
SubString =newstring[4:8]
Print(“Sub string is”,Substring)
Result:
Input: 
String1 = Guru // Create String1
String2 = Nanak // Create String2
Output:
Concatenation of two strings is GuruNanak
SubString is Nanak



#################
2. Write a program to perform different Arithmetic Operations on numbers in Python.
Aim: To perform different Arithmetic Operations on numbers in Python Programming.
Description:
The arithmetic operations are performed by calculator where we can perform addition, 
subtraction, multiplication, modulus, power and division. This example shows the basic 
arithmetic operations i.e.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the python programs
Program:
num1 = int(input(‘Enter First number’))
num2 = int(inut(‘Enter Second number’))
add = num1 + num2
sub = num1 – num2
div = num1 / num2
mul = num1 * num2
power = num1 ** num2
floor_div = num1 // num2
modulus = num1% num2
print(‘Sum of num1 and num2 is’,add)
print(‘Subtraction of num1 and num2 is’,sub)
print(‘Division of num1 and num2 is’,div)
print(‘floor division of num1 and num2 is’,floor_div)
print(‘power of num1 and num2 is’,power)
print(‘Modulus of num1 and num2 is’,modulue)
Result:
Input: Enter First number: 10
Enter Second number: 5
Output: Sum of num1 and num2 is 15



###################
1. Write a program to demonstrate different number data types in Python.
Aim: To demonstrate different number data types in Python Programming and implement 
 number data types program in python.
Description:
Python supports integers, floating-point numbers and complex numbers. They are 
defined as int, float, and complex classes in Python.Integers and floating points are 
separated by the presence or absence of a decimal point. For instance, 5 is an integer 
where as 5.0 is a floating-point number.Complex numbers are written in the form, 
x + yj, where x is the real part and y is the imaginary part.We can use the type()
function to know which class a variable or a value belongs to and isinstance()
function to check if it belongs to a particular class.
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster 
processor with at least 64 MB RAM and 100 MB free disk space.
A working computer system with either Windows or Linux
A web browser either IE or Fire Fox
Python 3.7
Prerequisites: Student must know how to install python 3.7 and run the basic programs.
Program:
a=10
print(a, “is of type,type(a))
a=3.0
print(a, “is of type,type(a))
a=1+3j
print(a, “is complex number?”, isInstance(1+3j,complex)
Result: 
Input: a=10,a=3,a=1+3j
Output:
10 is of type <class ‘int’>
3 is of type <class ‘float’>
1+3j is complex number? True



Raw Text