Skip to content

Commit f04d8b8

Browse files
committed
Debugged Python code
1 parent 83c81c3 commit f04d8b8

File tree

6 files changed

+174
-0
lines changed

6 files changed

+174
-0
lines changed

Aditya-abs397_solutions/boss.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
choice = 'y'
2+
3+
while choice =='y' : # make 'Y' valid too
4+
try:
5+
# typecast the below 2 to a list
6+
7+
numbers =input("Enter the input numbers separated by spaces: ")
8+
operators = input("Enter operators between them: ")
9+
10+
# check length matching
11+
12+
if len(numbers) != len(operators): # this seems odd... u might say it's ... off by one
13+
print("What u doin fam ? ") # replace wiht better message :)
14+
continue
15+
16+
flag = False # huh this seems inverted
17+
for i in range(len(numbers)): # indexing range fix
18+
a, b, op = numbers[i-1], numbers[i], operators[i]
19+
# correct the ops
20+
match op:
21+
case '+':
22+
c = a + b
23+
case '-':
24+
c = a * b
25+
case '*':
26+
c = a / b
27+
case '/':
28+
c = a % b
29+
case '%':
30+
c = a - b
31+
case '//':
32+
c = a ** b
33+
case '**':
34+
c = a // b
35+
case _:
36+
flag = True
37+
if not flag:
38+
print("Invalid ops vro")
39+
break
40+
41+
numbers[i-1] = c
42+
if not flag:
43+
continue
44+
print(f"Output: numbers[-1]")
45+
except Exception:
46+
print(f"Exception: ...") # print exception
47+
finally:
48+
choice = input("Do you want to continue? [y/n] : ") # always ask before ending
49+
50+
# can you make the code shorter and with improved answer?
51+
# like handling any basic arithmetic equation (that may have brackets too) ?
52+
# u might wanna find a special function in python
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# correct if else ladder to check if person is underage, normal citizen or senior citizen
2+
# [0,18) -> underage, [18,60) normal age, [60,inf) senior citizen
3+
# bonus, can you reduce ladder to a one liner?
4+
age = int(input("Enter age : ")) # ahh yes age is str , definitely
5+
6+
if age < 18:
7+
print("Lil bro")
8+
elif age <= 60:
9+
print("Pay up taxes, person")
10+
else:
11+
print("U still good, unc?")
12+
13+
14+
#BONUS
15+
print("Lil Bro u are coming to island ;}" if age<18 else "Forgot the files already" if age <= 60 else "just count ur sins")
16+
17+
# complete the match
18+
print("The week indexing is like 1 stands for monday and 7 for sunday")
19+
day = int(input("Enter the day number : ")) # dont forget to typecast to int
20+
21+
print("Today is: ", end="") # how can you avoid printing newline here?
22+
23+
match day:
24+
case 1:
25+
print("Monday")
26+
# fill in the rest
27+
case _:
28+
print("Funday !")
29+
30+
# implement try catch
31+
32+
try:
33+
print(1/0)
34+
except ZeroDivisionError: # ahh fix the syntax, also when u don't know the error what will u use?
35+
print("lmao what do u are? Newton")
36+
finally:
37+
print("So u done? just check ur deeds")

Aditya-abs397_solutions/hello.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# yayy
2+
print("Hello World")
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# typecast all inputs as prompted
2+
3+
# note: all inputs are strs by default
4+
5+
6+
integer = int(input("Enter an integer: ")) # change only this line
7+
8+
print(type(integer)) # should output 'int'
9+
10+
number = float(input("Enter a number (floating point allowed): ")) # change only this line
11+
12+
print(type(number)) # should output 'float'
13+
14+
array = list(map(float, input("Enter an array of numbers: ").split())) # change only this line
15+
16+
print(type(array)) # should output 'list'
17+
18+
nums = [1,2,3,4]
19+
20+
print(nums) # print it as a string joined by commas : 1,2,3,4
21+
22+
23+
name = input("Enter your name: ")
24+
25+
print(f"Hello, {name}") # complete f string
26+
27+
x,y,z = 67, 420 , 9000
28+
29+
30+
# 6 print statements is too much, can you get the same output in one print statement ?
31+
#Done
32+
print(f"x: {x},\n, y: {y},\n ,z: {z}")
33+
34+

Aditya-abs397_solutions/loops.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# print all multiples of 5 in [1,100]
2+
3+
for i in range(0,101): # start, stop, step , range is [start,stop)
4+
if(i%5 == 0):
5+
print(i,"\n")
6+
7+
8+
names = ["Avanish","Awwab","Nathan"]
9+
nicknames = ["Amar","Akbar","Anthony"]
10+
11+
for name,nickname in zip(names, nicknames): # wow cool new function
12+
print("Name:"+name +" Nickname:" + nickname + "/n") # fill this at least
13+
14+
# try zip for adding this array to the above 2 and printing all 3 in loop
15+
hobbies = ["Marvel","Anime","Games"]
16+
for name,nickname,hobby in zip(names, nicknames , hobbies):
17+
print("Name:"+name +" Nickname:" + nickname +" Hobby :" + hobby)
18+
19+
choice = input("Enter choice [y/n] : ")
20+
choice = 'y'
21+
22+
while choice == 'y':
23+
print("ok") # can you make this case insensitive with one more condition?
24+
25+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# declare some variables
2+
3+
x = 10
4+
y = 5
5+
6+
print(x+y) # come on think, this ain't javascript
7+
8+
num1 , num2 = 6 , 7
9+
10+
print(num1 // num2) # huh this shouldnt output 0, as a bonus can u also round to 2 decimal places?
11+
12+
a , n = 1, 31
13+
14+
a = 2 ** n
15+
16+
17+
# match the correct statements wrt bitwise operators
18+
19+
print("AND operator:", " & ")
20+
print("OR operator:", " | ")
21+
print("XOR operator:", " ^ ")
22+
23+
24+

0 commit comments

Comments
 (0)