Python File
Python File
Computer
Science
Project
Step 2) Once the download is completed, run the .exe file to install Python. Now click on Install Now
Step 3) You can see Python installing at this point.
Step 4) When it finishes, you can see a screen that says the Setup was successful. Now click on “Close”.
2. Learning about installation of Jupyter Notebook or Pycharm
Step 1) To download PyCharm visit the website https://www.jetbrains.com/pycharm/download/ and Click the
“DOWNLOAD” link under the Community Section.
Step 2) Once the download is complete, run the exe for install PyCharm. The setup wizard should have started. Click
“Next”.
Step 3) On the next screen, Change the installation path if required. Click “Next”.
Step 4) On the next screen, you can create a desktop shortcut if you want and click on “Next”.
Step 5) Choose the start menu folder. Keep selected JetBrains and click on “Install”.
Step 8) After you click on “Finish,” the Following screen will appear
3. Running instructions in Interactive interpreter and a Python Script
Open command prompt and type python or python3 and click Enter
Open Python 3.10 IDE and print “Hello World” and press Enter.
4. Write a program to purposefully raise Indentation Error and Correct it
Input:
print(a)
Output:
Input:
print(a)
Output:
5. Operations
1. Write a program to compute distance between two points taking input from the user.
x1=int(input("enter x1 : "))
x2=int(input("enter x2 : "))
y1=int(input("enter y1 : "))
y2=int(input("enter y2 : "))
2. Write a program to find sum, difference, product, quotient, remainder of two numbers taking input
from user.
1. Write a Program for checking whether the given number is an even number or not.
n = int(input("Enter a number: "))
if n%2==0:
print("Even number")
2. Using a for loop, write a program that prints out the decimal equivalents of 1/2, 1/3, 1/4, . . .,
1/10.
for i in range(2,11):
print(1/i)
3. Write a program to find prime factors of a number by taking inputs from user
4. def primefactor(n):
while (n%2==0):
print(2)
n=n/2
for i in range(3, int(n)):
while n%i==0:
print(i)
n=n/i
if(n>2):
print(n)
n= int(input("Enter a number: "))
primefactor(n)
4. Write a program using a while loop that asks the user for a number, and prints a countdown
from that number to zero.
while(n>0):
n -= 1 print(n)
5. Write a program to find whether a number is prime or not such that number is input by user.
def primenumber(n):
h=False
for i in range(2,n):
if n%i==0:
h=True
break
if h:
primenumber(n)
6. Write a program to print Fibonacci series using loops.
a=0
b=1
for i in range(0,n):
print(a)
c=a+b
a=b
b=c
i+=1
count=0
r=num%10
count=count + (r**3)
num//=10
if count==n:
print("armstrong number")
else: print("not")
8. Write to find sum of squares till the number input by the user.
n= int(input("Enter a number: "))
count=0
count=count + (i**2)
print(count)
9. Write the code for following patterns:
a.
row = int(input("Enter a number: "))
for i in range(1,row+1):
for c in range(1,i+1):
print(c, end=" ")
print(" ")
b.
for i in range (0,6):
print(" ",end="")
print("")
for i in range(0,5):
print("* ",end="")
print()
c.
n = int ( input ("Enter a number : ") )
else:
print(end=" ")
print()
A.
B.
C.
10. Write a program to print pascal’s triangle.
def fact(n):
ans=1
ans*=i
return int(ans)
for i in range(0,n):
for k in range(n,i,-1):
print()
answer=1
answer*=i
print(answer)
output:-
def collision():
dist=((((q-b)**2) + ((p-a)**2))**0.5)
sum=r1+r2
if dist<=sum:
collision()
r=x%y if(r==0):
return y
else:
return GCD(y,r)
def lcm(a,b):
lcm.multiple=lcm.multiple+b
return lcm.multiple;
else: lcm(a, b)
return lcm.multiple
lcm.multiple=0
if(a>b):
LCM=lcm(b,a)
else:
LCM=lcm(a,b)
OUTPUT :-
a.with recursion
#fibonacci program
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
if nterms <= 0:
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
#factorial program
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
num = int(input("Enter a number: "))
if num < 0:
elif num == 0:
b. without recursion
#fibonacci
def fibonacci():
f = 0
s = 1
if a <= 0:
else:
print(f) print(s)
next = f + s print(next)
f = s
s = next
fibonacci()
#factorial
def factorial(num):
factorial = 1
if num < 0:
elif num == 0:
else:
factorial = factorial*i
factorial(num)
OUTPUT:-
if (disks == 1):
disks = 4
if string1 == string2:
else:
OUTPUT:-
2. Write a function to find whether a string is palindrome or not.
def isPalindrome(s):
return s == s[::-1]
ans = isPalindrome(s)
if ans:
print("a palindrome")
else:
print("Not a palindrome")
OUTPUT:-
3. Write a program to find number of P’s in “Problem Solving using Python”
n=0
for i in range(0,len(s)):
if (s[i]=="P") or (s[i]=="p"):
n+=1
num=[a,b,c]
sum=0
if num[i]%2==0:
OUTPUT:-
2. Write a program that finds the sum of all the numbers in a Tuples using while loop.
tuple = (a, b, c)
s = 0
i = 0
s = s + tuple[i]
i+= 1
OUTPUT:-
# initializing dictionary
res = dict(reversed(list(test_dict.items())))
OUTPUT:-
l=[11,22,11,33,45,54,99,99,88,767,767,98,69,54,65,76,32,69,90,21,21,34,32]
l1=[]
for i in l:
if i not in l1:
l1.append(i)
else:
print(i,end=' ')
OUTPUT:-
5. Write a program unique to find all the unique elements of a list.
my_list = [11,2,45,32,66,987,54,69,69,33,11,2]
my_set = set(my_list)
my_new_list = list(my_set)
OUTPUT:-
def product(list):
p =1
for i in list:
p *= i
print(p)
return p
list= [1,2,3,4,5,6,7,8,9,10]
c=product(list)
OUTPUT:-
7. Find mean, median, mode for the given set of numbers in a list.
def find_mean(numbers):
def find_median(numbers):
if len(numbers) % 2 == 0:
return (numbers[(len(numbers) - 1) // 2] +
numbers[(len(numbers) + 1) // 2]) / 2
return numbers[len(numbers) // 2]
frequency = 0
for i in range(len(numbers)):
if numbers[i] == number:
frequency += 1
return frequency
def find_max_frequency(frequencies):
return max(frequencies)
def find_modes(numbers):
frequencies = []
frequencies.append(frequency)
max_frequency = find_max_frequency(frequencies)
modes = []
modes.append(number)
return modes
numbers = [12, 435, 12, 46, 565, 87, 867, 998, 90, 32, 432, 87]
numbers.sort()
mean = find_mean(numbers)
median = find_median(numbers)
modes = find_modes(numbers)
8. Given the sets A={“Arush”, “Sunita”, 89, 98.5} & B={89, “DSEU”}
Write a program to find the following:
a) Union of two sets
b) Intersection of two sets
c) Symmetric Difference of two sets
d) Difference of two sets
b = {89, "DSEU"}