-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9d3767
commit 9fda1f0
Showing
8 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
while True: | ||
try: | ||
num=int(input("enter a number from 0-942: ")) | ||
if num>= 0 and num <= 942 : | ||
break | ||
else: | ||
print("invalid data entered pls try again") | ||
except : | ||
print("invalid data entered pls try again") | ||
def ones(no): | ||
|
||
if no==100: | ||
return 21 | ||
elif no > 100 and no <200: | ||
return 21+1*(no-100) | ||
elif no > 100 and no < 940 : | ||
return 120 +((no/100)-1)*20 | ||
elif no==10: | ||
return 2 | ||
elif no>10 and no< 100: | ||
return 10+(no/10) | ||
elif no<10 and no!=0: | ||
return 1 | ||
else: | ||
return 0 | ||
no_of_ones=int(0) | ||
firstdigit=num | ||
secondigit=0 | ||
thirdigit=0 | ||
if firstdigit<200 and firstdigit>100: | ||
thirdigit=int(firstdigit%10) | ||
secondigit=(firstdigit/10)%10 | ||
|
||
no_of_ones=ones(firstdigit)+ones(secondigit*10)+ones(thirdigit) | ||
elif firstdigit/10 >=10: | ||
thirdigit=firstdigit%10 | ||
firstdigit=firstdigit/10 | ||
secondigit=int(firstdigit%10) | ||
firstdigit=int(firstdigit/10) | ||
no_of_ones=ones(firstdigit*100)+ones(secondigit*10)+ones(thirdigit) | ||
|
||
|
||
|
||
elif firstdigit/10 < 10 and firstdigit!=0: | ||
secondigit=firstdigit | ||
thirdigit=secondigit%10 | ||
secondigit=int(secondigit/10) | ||
no_of_ones=int(ones(secondigit*10))+int(ones(thirdigit)) | ||
|
||
|
||
|
||
|
||
else: | ||
thirdigit=firstdigit | ||
no_of_ones=int(ones(thirdigit)) | ||
|
||
|
||
print("number of ones in ",num," is ",no_of_ones) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import this | ||
|
||
thisbox=[23,32,63,23,5,6] | ||
def printf(): | ||
print(thisbox) | ||
def removee(item): | ||
if item==0: | ||
thisbox.remove() | ||
else: | ||
thisbox.remove(item) | ||
def additem(item): | ||
thisbox.append(item) | ||
while True: | ||
printf() | ||
try: | ||
user_command=input("type enter or remove: ") | ||
if user_command=="remove": | ||
|
||
user_remove=input("remove any or remove a specific NO.: ") | ||
if user_remove=="remove any": | ||
if thisbox.count==5: | ||
print("can't romve anymore") | ||
else: | ||
removee(0) | ||
elif user_remove=="specific": | ||
item=int(input("enter the number you want to remove")) | ||
if thisbox.count==5: | ||
print("can't romve anymore") | ||
else: | ||
removee(item) | ||
elif user_command=="enter": | ||
item=int(input("enter the number you want to add: ")) | ||
additem(item) | ||
except: | ||
print("invalid input try again ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
def raise_1(ex): | ||
raise ex | ||
|
||
class user_entered_Q(Exception): | ||
pass | ||
|
||
list =[] | ||
|
||
while True: | ||
try: | ||
|
||
check = lambda x : raise_1(user_entered_Q()) if x=='q' else list.append(int(x)) | ||
check(input("pls enter a number: ")) | ||
|
||
except user_entered_Q: | ||
break | ||
except ValueError: | ||
print("invaild data entry try again") | ||
largest = max(list) | ||
smallest =min(list) | ||
print("largest number is ",largest) | ||
print("smallest number is ",smallest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
list_1=[] | ||
list_2=[] | ||
while True: | ||
z=input("enter the names ffs: ") | ||
if z.isalpha() and z != "q" or z.__contains__(" "): | ||
list_1.append(z) | ||
elif z == "q": | ||
break | ||
else: | ||
print("invalid data entry ") | ||
while True: | ||
z=input("enter the names in list2 ffs: ") | ||
if z.isalpha() and z != "q" or z.__contains__(" "): | ||
list_2.append(z) | ||
elif z == "q": | ||
break | ||
else: | ||
print("invalid data entry ") | ||
mutual=[x for x in list_1 if x in list_2 ] | ||
print(mutual) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import datetime | ||
|
||
def calculate_age(birthday): | ||
today = datetime.date.today() | ||
age = today.year - birthday.year | ||
return age | ||
|
||
def input_entry(): | ||
while True: | ||
try: | ||
name, birthday_str = input("Input your entry (name, DD/MM/YYYY): ").split(", ") | ||
birthday = datetime.datetime.strptime(birthday_str, "%d/%m/%Y").date() | ||
if birthday > datetime.date.today(): | ||
raise ValueError("Upcoming birthday") | ||
if not name.isalpha(): | ||
raise ValueError("Name containing number") | ||
age = calculate_age(birthday) | ||
name = name.capitalize() | ||
database[name] = {"birthday": birthday, "age": age} | ||
print(f"Successfully entered: {name}, {age} years old") | ||
break | ||
except ValueError as e : | ||
print(e) | ||
|
||
def read_entries(): | ||
print("List of entries:") | ||
for name in database: | ||
entry = database[name] | ||
print(f"{name}, {entry['age']} years old") | ||
|
||
def delete_entry(): | ||
name = input("Input the name of the entry you want to delete: ").capitalize() | ||
if name in database: | ||
del database[name] | ||
print(f"Successfully deleted: {name}") | ||
else: | ||
print(f"{name} not found in the database") | ||
|
||
database = {} | ||
|
||
while True: | ||
action = input("What do you want to do (input, read, delete, exit): ") | ||
if action == "input": | ||
input_entry() | ||
elif action == "read": | ||
read_entries() | ||
elif action == "delete": | ||
delete_entry() | ||
elif action == "exit": | ||
print("Goodbye") | ||
break | ||
else: | ||
print("Invalid action") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import cv2 | ||
import random | ||
|
||
def display_result(winner): | ||
if winner== "user": | ||
background = cv2.imread("D:\pissed-off-face-winner-meme.jpg") | ||
text=username+" Won!" | ||
|
||
elif winner== "computer" : | ||
background = cv2.imread("D:\Dark_Souls_You_Died_Screen_-_Completely_Black_Screen_0-2_screenshot.jpg") | ||
text = "You lost." | ||
|
||
background = cv2.resize(background, (500, 500)) | ||
|
||
cv2.putText(background, text, (100, 250), cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255), 2) | ||
|
||
cv2.imshow("Result", background) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
||
|
||
|
||
|
||
def play_game(username): | ||
bags = [10, 10, 10] | ||
turn = 'user' | ||
|
||
while sum(bags) > 0: | ||
if turn == 'user': | ||
print(f'Bags: {bags}') | ||
bag_choice = -1 | ||
while bag_choice not in [0, 1, 2] or bags[bag_choice] == 0: | ||
try: | ||
bag_choice = int(input('Choose a bag (1, 2, or 3): ')) - 1 | ||
if bag_choice not in [0, 1, 2]: | ||
print('Invalid bag choice. Please choose a valid bag number (1, 2, or 3).') | ||
elif bags[bag_choice] == 0: | ||
print('Bag is already empty. Please choose another bag.') | ||
except ValueError: | ||
print('Invalid bag choice. Please enter a number (1, 2, or 3).') | ||
num_objects = -1 | ||
while num_objects < 1 or num_objects > 5 or num_objects > bags[bag_choice]: | ||
try: | ||
num_objects = int(input('Choose the number of objects to remove (1-5): ')) | ||
if num_objects < 1 or num_objects > 5: | ||
print('Invalid number of objects. Please enter a number between 1 and 5 (inclusive).') | ||
elif num_objects > bags[bag_choice]: | ||
print(f'Not enough objects in the bag. Please enter a number between 1 and {bags[bag_choice]}.') | ||
except ValueError: | ||
print('Invalid number of objects. Please enter a number (1-5).') | ||
bags[bag_choice] -= num_objects | ||
if sum(bags) == 0: | ||
return 'user' | ||
turn = 'computer' | ||
else: | ||
bag_choice = random.randint(0, 2) | ||
while bags[bag_choice] == 0: | ||
bag_choice = random.randint(0, 2) | ||
num_objects = random.randint(1, min(5, bags[bag_choice])) | ||
print(f'Computer removed {num_objects} from bag {bag_choice + 1}') | ||
bags[bag_choice] -= num_objects | ||
if sum(bags) == 0: | ||
return 'computer' | ||
turn = 'user' | ||
|
||
username = input('Enter your username: ') | ||
result = play_game(username) | ||
display_result(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import random | ||
def raise_1(ex): | ||
raise ex | ||
def coin_toss(): | ||
list_1=["heads","tail"] | ||
print(random.sample(list_1,k=1)) | ||
def Rand_Num(): | ||
d=input("enter the range of numbers: ") | ||
list_2=d.split() | ||
if int(list_2[0]) > int(list_2[-1]): | ||
print("The random number : ",random.randrange(int(list_2[-1]),int(list_2[0]))) | ||
elif int(list_2[0]) < int(list_2[-1]): | ||
print("The random number : ",random.randrange(int(list_2[0]),int(list_2[-1]))) | ||
else: | ||
print("invalid range try again, Game Over!") | ||
|
||
def Random_choice(): | ||
i=input("enter your choices: ") | ||
list_3=i.split() | ||
print("the random choice is : ",random.sample(list_3,k=1)) | ||
|
||
class user_entered_exit(Exception): | ||
pass | ||
class out_of_range(Exception): | ||
pass | ||
|
||
#while True: | ||
# try: | ||
|
||
# check = lambda x : raise_1(user_entered_exit()) if x=="exit" else int(x) | ||
# z=check(input("pls choose game from 1-3 : ")) | ||
#if z < 0 or z > 3 : | ||
# raise_1(out_of_range) | ||
#print(z) | ||
#if z==1: | ||
# coin_toss() | ||
#elif z==2: | ||
# Rand_Num() | ||
#elif z==3: | ||
# Random_choice() | ||
#except user_entered_exit: | ||
# break | ||
#except ValueError: | ||
# print("invaild data entry try again") | ||
#except out_of_range: | ||
# print("out of range pls choose from 1-3!") |
Oops, something went wrong.