Shivam Python Last
Shivam Python Last
num=int(input("Enter a number:"))
temp=num
rev=0
while(num>0):
dig=num%10
rev=rev*10+dig
num=num//10
if(temp==rev):
print("The number is palindrome!")
else:
print("Not a palindrome!")
Output:
Enter a number:121
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
Output:
factorial = 1
if num < 0:
elif num == 0:
else:
factorial = factorial*i
Output:
The factorial of 4 is 24
NAME: SHIVAM NEGI
COURSE – BCA 4 ‘C1’
ROLL NO.:68
n1, n2 = 0, 1
count = 0
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth , count += 1
Output:
Fibonacci sequence:
NAME: SHIVAM NEGI
COURSE – BCA 4 ‘C1’
ROLL NO.:68
my_sum = 0
if(n % i == 0):
my_sum = my_sum + i
if (my_sum == n):
else:
Output:
Output:
Output:
my_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = []
unique_list.append(item)
print(unique_list)
Output:
[1, 2, 3, 4, 5]
NAME: SHIVAM NEGI
COURSE – BCA 4 ‘C1’
ROLL NO.:68
modified_list = []
modified_list.append(item)
modified_tuple = tuple(modified_list)
print(modified_tuple)
Output:
cubes = {}
cubes[num] = num**3
print("Values:",cubes.values())
cubes.clear()
Output:
def count_vowels(text):
vowel_count = 0
if char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u'
or \ char == 'A' or char == 'E' or char == 'I' or char == 'O' or char ==
'U': vowel_count += 1
return vowel_count
vowel_count = count_vowels(user_text)
Output:
PROBLEM STATEMENT 12: A shop will give discount of 10% if the cost
of purchased quantity is more than 1000 rupees. Now write a
python program having a user defined function which will first
calculate whether a user purchased quantities more than 1000
rupees or not and then accordingly it will print the total cost for
user.
cost -= discount
return cost
print("Total cost for", quantity, "items at", price, "rupees per item:",
total_cost, "rupees (no discount applied)")
else:
Output:
Total cost for 3 items at 800.0 rupees per item: 2160.0 rupees (discount of 240.0
rupees applied)
NAME: SHIVAM NEGI
COURSE – BCA 4 ‘C1’
ROLL NO.:68
if years_of_service > 5:
bonus_percentage = 0.05
return bonus_amount
else:
return 0
if bonus_amount > 0:
print("The net bonus amount for the employee is:", bonus_amount, "rupees.")
else:
print("The employee is not eligible for a bonus (less than 5 years of service).")
Output:
The net bonus amount for the employee is: 1250.0 rupees.