Skip to main content

Differentiate Between type() and instance()

0 likes • May 31, 2023 • 0 views
Python
Loading...

More Python Posts

Find Coin

0 likes • Oct 4, 2023 • 8 views
Python
weigh = lambda a,b: sum(b)-sum(a)
FindCoin = lambda A: 0 if (n := len(A)) == 1 else (m := n//3) * (w := 1 + weigh(A[:m], A[2*m:])) + FindCoin(A[m*w:m*(w+1)])
print(FindCoin([1,1,1,1,1,1,1,2,1]))

Mad libs generator

0 likes • Nov 19, 2022 • 0 views
Python
#Loop back to this point once code finishes
loop = 1
while (loop < 10):
#All the questions that the program asks the user
noun = input("Choose a noun: ")
p_noun = input("Choose a plural noun: ")
noun2 = input("Choose a noun: ")
place = input("Name a place: ")
adjective = input("Choose an adjective (Describing word): ")
noun3 = input("Choose a noun: ")
#Displays the story based on the users input
print ("------------------------------------------")
print ("Be kind to your",noun,"- footed", p_noun)
print ("For a duck may be somebody's", noun2,",")
print ("Be kind to your",p_noun,"in",place)
print ("Where the weather is always",adjective,".")
print ()
print ("You may think that is this the",noun3,",")
print ("Well it is.")
print ("------------------------------------------")
#Loop back to "loop = 1"
loop = loop + 1

print colored text to IDE terminal

0 likes • Jun 1, 2023 • 0 views
Python
from colorama import init, Fore
# Initialize colorama
init()
print(Fore.RED + "This text is in red color.")
print(Fore.GREEN + "This text is in green color.")
print(Fore.BLUE + "This text is in blue color.")
# Reset colorama
print(Fore.RESET + "This text is back to the default color.")

UNT CSCE 2100 Question 1

0 likes • Nov 18, 2022 • 1 view
Python
#question1.py
def rose(n) :
if n==0 :
yield []
else :
for k in range(0,n) :
for l in rose(k) :
for r in rose(n-1-k) :
yield [l]+[r]+[r]
def start(n) :
for x in rose(n) :
print(x) #basically I am printing x for each rose(n) file
print("starting program: \n")
start(2) # here is where I call the start function

return multiple values from a function

0 likes • Jun 1, 2023 • 0 views
Python
def calculate_values():
value1 = 10
value2 = 20
return value1, value2
result1, result2 = calculate_values()
print("Result 1:", result1)
print("Result 2:", result2)

Calculator

0 likes • Nov 19, 2022 • 0 views
Python
""" Calculator
----------------------------------------
"""
def addition ():
print("Addition")
n = float(input("Enter the number: "))
t = 0 //Total number enter
ans = 0
while n != 0:
ans = ans + n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def subtraction ():
print("Subtraction");
n = float(input("Enter the number: "))
t = 0 //Total number enter
sum = 0
while n != 0:
ans = ans - n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def multiplication ():
print("Multiplication")
n = float(input("Enter the number: "))
t = 0 //Total number enter
ans = 1
while n != 0:
ans = ans * n
t+=1
n = float(input("Enter another number (0 to calculate): "))
return [ans,t]
def average():
an = []
an = addition()
t = an[1]
a = an[0]
ans = a / t
return [ans,t]
// main...
while True:
list = []
print(" My first python program!")
print(" Simple Calculator in python by Malik Umer Farooq")
print(" Enter 'a' for addition")
print(" Enter 's' for substraction")
print(" Enter 'm' for multiplication")
print(" Enter 'v' for average")
print(" Enter 'q' for quit")
c = input(" ")
if c != 'q':
if c == 'a':
list = addition()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 's':
list = subtraction()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'm':
list = multiplication()
print("Ans = ", list[0], " total inputs ",list[1])
elif c == 'v':
list = average()
print("Ans = ", list[0], " total inputs ",list[1])
else:
print ("Sorry, invilid character")
else:
break