Skip to content

Commit 3c585a0

Browse files
fixed codes
1 parent c347ef2 commit 3c585a0

File tree

5 files changed

+39
-42
lines changed

5 files changed

+39
-42
lines changed

ques_2.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
def calc(sales):
3-
total_sales = 4*sales
2+
def calc(sale1, sale2, sale3, sale4):
3+
total_sales = sale1+sale2+sale3+sale4
44
com_amt = 0 #Commission
55
if total_sales >= 50000:
66
com_amt = total_sales*0.05
@@ -17,9 +17,12 @@ def calc(sales):
1717
return total_sales, com_amt, remarks
1818

1919
if __name__ == "__main__":
20-
sales = int(input("Enter the sales per week: "))
21-
t_sales, comm, remarks = calc(sales)
20+
sale1 = int(input("Enter the sales for week 1: "))
21+
sale2 = int(input("Enter the sales for week 2: "))
22+
sale3 = int(input("Enter the sales for week 3: "))
23+
sale4 = int(input("Enter the sales for week 4: "))
24+
t_sales, comm, remarks = calc(sale1, sale2, sale3, sale4)
2225

2326
print("Total Sales: Rs.{:.2f}".format(t_sales))
2427
print("Commission: Rs.{:.2f}".format(comm))
25-
print("Remarks: ", remarks)
28+
print("Remarks:", remarks)

ques_3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ def factorial(n):
66

77
# Fibonacci function to find nth term of series
88
def fib(n): #Recursive
9-
if n <= 1:
9+
if n <= 0:
10+
return 0
11+
if n == 1:
1012
return 1
1113
return fib(n-1) + fib(n-2)
1214

ques_5.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
def sum_series(x, n):
66
sum = 0
77
for i in range(1, n+1, 1):
8-
term = x**(2*i-2)/factorial(2*i-2) #Calculating nth term
9-
if i % 2 == 0:
10-
sum -= term
11-
else:
12-
sum += term
8+
term = ((-1)**(i+1))*(x**(2*i-2)/factorial(2*i-2)) #Calculating nth term
9+
sum += term
1310
return sum
1411

1512
if __name__ == "__main__":

ques_7.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ def maxof_three():
77
str2= input("Enter string 2: ")
88
str3 = input("Enter string 3: ")
99
maxstr = ""
10-
if len(str1) > len(str2) and len(str1) > len(str3):
10+
if str1 > str2 and str1 > str3:
1111
maxstr = str1
12-
elif len(str2) > len(str1) and len(str2) > len(str3):
12+
elif str2 > str1 and str2 > str3:
1313
maxstr = str2
1414
else:
1515
maxstr = str3
@@ -45,31 +45,33 @@ def palindrome():
4545
else:
4646
print(f"{str} is not a palindrome")
4747

48+
def main():
49+
print("\nMenu")
50+
print("-"*20)
51+
print("1. Length of string")
52+
print("2. Maximum of three strings")
53+
print("3. Replace vowels with '#'")
54+
print("4. No. of words")
55+
print("5. Check Palindrome")
56+
print("6. Exit")
57+
print("-"*20)
58+
option = input("Your choice: ")
59+
60+
switcher = {
61+
'1' : len_str,
62+
'2' : maxof_three,
63+
'3' : replace_vowels,
64+
'4' : numofwords,
65+
'5' : palindrome,
66+
'6' : quit
67+
}
68+
func = switcher.get(option, lambda: print("Invalid Choice!"))
69+
func()
70+
4871
if __name__ == "__main__":
4972

5073
ch = 'y'
5174
while ch.lower() == 'y':
52-
print("\nMenu")
53-
print("-"*20)
54-
print("1. Length of string")
55-
print("2. Maximum of three strings")
56-
print("3. Replace vowels with '#'")
57-
print("4. No. of words")
58-
print("5. Check Palindrome")
59-
print("6. Exit")
60-
print("-"*20)
61-
option = input("Your choice: ")
62-
63-
switcher = {
64-
'1' : len_str,
65-
'2' : maxof_three,
66-
'3' : replace_vowels,
67-
'4' : numofwords,
68-
'5' : palindrome,
69-
'6' : quit
70-
}
71-
func = switcher.get(option, lambda: print("Invalid Choice!"))
72-
func()
73-
75+
main()
7476
ch = input("\nWant to continue? [y/n]: ")
7577

ques_8.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,18 @@ def common(l1, l2):
7878
print("All elements are numbers")
7979
else:
8080
print("All elements are not numbers")
81-
8281
count_odd(l)
83-
8482
largest_str(l)
85-
8683
print("Reversed list:", end=" ")
8784
display_reverse(l)
88-
8985
item = input("\nEnter an element: ")
9086
find_item(item,l)
91-
9287
remove_item(item, l)
93-
9488
print("Sorted in Descending Order: ")
9589
print(sort_desc(l))
9690
l2 = []
9791
n = int(input("Enter the size of new list: "))
9892
for i in range(0, n, 1):
9993
l2.append(input("Enter element: "))
100-
10194
common(l, l2)
10295

0 commit comments

Comments
 (0)