Skip to content

Commit 3c77e73

Browse files
committed
Home: Upload last minute prep codes
1 parent f3aa699 commit 3c77e73

23 files changed

+290
-7
lines changed

amicable_number.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from re import L
2+
3+
4+
A = int(input("Enter your first number: "))
5+
B = int(input("Enter your second number: "))
6+
7+
f1,f2 = 0,0
8+
9+
for i in range(1,A):
10+
if (A%i == 0):
11+
f1+=i
12+
for j in range(1,B):
13+
if (B%j==0):
14+
f2+=j
15+
16+
if A==f2 and B==f1:
17+
print("They are amicable numbers")
18+
else:
19+
print('They are not the amicable numbers')

ams.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
arr=[]
2+
ams=0
3+
num = input("Enter the number: ")
4+
5+
if num!=int(num):
6+
pass
7+
for i in num:
8+
arr.append(int(i))
9+
for j in arr:
10+
ams+=j**3
11+
12+
num=int(num)
13+
if num==ams:
14+
print("The given number is an ams num")
15+
else:
16+
print("The given number is not an ams number")
17+
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import math
2+
class Circle:
3+
def __init__(self,radius):
4+
self.radius=radius
5+
def area(self):
6+
return math.pi*(self.radius**2)
7+
def perimeter(self):
8+
return 2*math.pi*self.radius
9+
10+
r=int(input("Enter the radius: "))
11+
obj = Circle(r)
12+
print(f"Area: {round(obj.area(),4)}")
13+
print(f"Perimeter: {round(obj.perimeter(),4)}")

cla.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import sys
2+
n = len(sys.argv)
3+
if n==1:
4+
print("No arguments passed")
5+
else:
6+
sum = 0
7+
for i in sys.argv[1:]:
8+
sum=int(i)+sum
9+
print(f"Sum of the numbers passed through args is: {sum}")
10+

date.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
date = input("Enter the date in DD-MM-YYYY Format: ")
2+
day, month, year = date.split('-')
3+
4+
day = int(day)
5+
year = int(year)
6+
month = int(month)
7+
8+
# Lets input 28-02-2022
9+
10+
# check if the month is leap year
11+
12+
if month in [1, 3, 5, 7, 8, 10, 12]:
13+
days = 31
14+
elif month != 2:
15+
days = 30
16+
elif year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
17+
days = 29
18+
else:
19+
days = 28
20+
21+
if month < 1 or month > 12 or day < 1 or day > days:
22+
print("Invalid date")
23+
elif day == days and month != 12:
24+
day = 1
25+
month += 1
26+
print(f"Incremented date: {day}-{month}-{year}")
27+
elif day == 31 and month == 12:
28+
day = 1
29+
month = 1
30+
year += 1
31+
print(f"Incremented date: {day}-{month}-{year}")
32+
else:
33+
day = day+1
34+
print(f"Incremented date: {day}-{month}-{year}")

display_largest_word.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
a = []
2+
3+
ran = int(input('Enter the number of elements in the list: '))
4+
for i in range(1,ran+1):
5+
element = input(f"Enter {i+1} Element: ")
6+
a.append(element)
7+
max=len(a[0])
8+
word=a[0]
9+
for i in a:
10+
if len(i)>max:
11+
max=len(i)
12+
temp = i
13+
14+
print("The word with the longest length is: ",temp)

exceptions.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class TheNameIsShravan(Exception):
2+
pass
3+
4+
raise TheNameIsShravan("You cannot set the name Shravan")
5+
6+

fib.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
terms = int(input("Enter a value: "))
2-
1+
terms = int(input("Enter number of terms: "))
32
n1,n2 = 0,1
43
count = 0
5-
64
if terms <=0:
7-
print("Please enter a positive integer,")
5+
print("Please enter a positive integer")
86
elif terms==1:
9-
print("Fibonacci sequence upto",terms,":")
7+
print(f"Fibonacci Sequence upto: {terms}: ")
108
print(n1)
119
else:
12-
print("Fibonacci sequence:")
10+
print("Fibonacci Sequence: ")
1311
while count<terms:
1412
print(n1)
1513
n3=n1+n2

gcd.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def gcd(x,y):
2+
while(y):
3+
x,y=y,x%y
4+
return x
5+
6+
A = int(input("Enter your first number: "))
7+
B = int(input("Enter your second number: "))
8+
print("GCD is",gcd(A,B))

givendate.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
d1 = input("Enter your date-1 seperated by '-': ")
2+
d2 = input("Enter your date-2 seperated by '-': ")
3+
4+
day,month,year = d1.split('-')

gui.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#from tkinter import *
2+
#from tkinter import messagebox
3+
#
4+
#window=Tk()
5+
#window.title("GUI Python")
6+
#window.resizable(0,0)
7+
#window.geometry('300x500')
8+
#MyVar=StringVar()
9+
#def compute():
10+
# val=MyVar.get()
11+
# k=int(val)
12+
# f=k*(9/5)+32
13+
# messagebox.showinfo('msg title','Farheinheit Value: '+str(f))
14+
#
15+
#l1=Label(text='Enter celcius value: ',font=100)
16+
#e1=Entry(text='Your input here',textvariable=MyVar,font=100)
17+
#btn=Button(text='Convert',font=100,command=compute)
18+
#l1.grid(column=1,row=0)
19+
#e1.grid(column=2,row=0)
20+
#btn.grid(row=1,column=1)
21+
#window.mainloop()
22+
from tkinter import *
23+
from tkinter import messagebox
24+
25+
from numpy import size
26+
27+
window=Tk()
28+
window.geometry('300x200')
29+
window.title("GUI Programt to convert Celcius to fahreinheit")
30+
MyVar=StringVar()
31+
def compute():
32+
val=MyVar.get()
33+
k=int(val)
34+
f=k*(9/5)+32
35+
messagebox.showinfo("Result",f"Converted Fahreinheit Value: {f}")
36+
37+
l1=Label(text="Enter your Celcius value: ",font=100)
38+
btn=Button(text="Convert",command=compute,font=100)
39+
e1=Entry(textvariable=MyVar,font=100)
40+
l1.grid(column=1,row=0)
41+
e1.grid(column=2,row=0)
42+
btn.grid(row=1,column=1)
43+
window.mainloop()

learn-python

-1
This file was deleted.

new.csv

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Location, Temperature
2+
Khammam, 34
3+
Hyderabad, 32
4+
Nadargul, 39
5+
Vijayawada, 31

noname.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write a Python GUI program to create two buttons exit and hello using tkinter module.
2+
3+
from tkinter import *
4+
5+
window = Tk()
6+
btn=Button(window,text="exit")
7+
btn2=Button(window,text="Hello")
8+
9+
btn.place(x=75,y=62)
10+
btn2.place(x=75,y=120)
11+
12+
window.title('Hello Python')
13+
window.geometry("300x200+10+10")
14+
window.mainloop()

number_of_occurences.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
items = [7,8,5,1,4,1,6,1,89,13,12,7,8,4,1,2,3,4,5,6]
2+
3+
x = int(input("Enter the value: "))
4+
print(items.count(x))

numpy_code.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import numpy as np
2+
#import pandas as pd
3+
size = int(input('Enter your size of the array: '))
4+
print("Enter",size,"Elements: ")
5+
num=0
6+
arr=[]
7+
for i in range(size):
8+
item=int(input())
9+
arr.append(item)
10+
11+
npl=np.array(arr)
12+
npl=npl.reshape(3,3)
13+
print(npl)
14+
print(np.sum(npl,axis=0)) # Rows
15+
print(np.sum(npl))
16+
print(np.sum(npl,axis=1)) # Columns

padnas.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pandas as pd
2+
import matplotlib.pyplot as plt
3+
k = pd.read_csv("new.csv")
4+
k.plot()
5+
plt.show()

possible_combinations.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
k = input("Enter your 3-digit number: ")
2+
3+
com=[]
4+
5+
for i in k:
6+
com.append(int(i))
7+
8+
for j in range(0,3):
9+
for w in range(0,3):
10+
for l in range(0,3):
11+
if j!=w and w!=l and l!=j:
12+
print(com[j],com[w],com[l])

ps.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import numpy as np
2+
k = np.arange(6,12).reshape(3,2)
3+
c = np.arange(15,21).reshape(2,3)
4+
print(k)
5+
#print(np.concatenate((k,c),axis=0))
6+
k.sort(0)
7+
print(k)

pyplot.py

Whitespace-only changes.

rand.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import random
2+
3+
A = random.randint(0,500)
4+
B = random.randint(45,500)
5+
6+
print(f"Q: What is {A} + {B} ?")
7+
resp = int(input("Enter your answer: "))
8+
9+
if resp!=A+B:
10+
print("Wrong answer")
11+
else:
12+
print("Right Answer")

remove_ith_occurence.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from xml.dom.minidom import Element
2+
3+
4+
a=[]
5+
n=int(input("Enter the number of elements in the list: "))
6+
for x in range(0,n):
7+
element = input(f"Enter element {x+1}: ")
8+
a.append(element)
9+
print(a)
10+
c=[]
11+
count=0
12+
b = input("Enter word to remove: ")
13+
n = int(input("Enter the occurence to remove: "))
14+
for i in a:
15+
if i==b:
16+
count+=1
17+
if count!=n:
18+
c.append(i)
19+
else:
20+
c.append(i)
21+
if count==0:
22+
print("Item not found")
23+
else:
24+
print(f"The number of repetetions are: {count}")
25+
print(f"Updated list is {c}")

strong.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def fact(n):
2+
if n == 1:
3+
return 1
4+
else:
5+
return n*fact(n-1)
6+
num = input("Enter your number: ")
7+
if num != int(num):
8+
pass
9+
arr = []
10+
strong = 0
11+
for i in num:
12+
arr.append(int(i))
13+
for j in arr:
14+
strong += fact(j)
15+
if strong == int(num):
16+
print("This is a strong number")
17+
else:
18+
print("This is not a strong number")

0 commit comments

Comments
 (0)