Loading...
More Python Posts
def max_n(lst, n = 1):return sorted(lst, reverse = True)[:n]max_n([1, 2, 3]) # [3]max_n([1, 2, 3], 2) # [3, 2]
#question1.pydef 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) fileprint("starting program: \n")start(2) # here is where I call the start function
from statistics import median, mean, modedef print_stats(array):print(array)print("median =", median(array))print("mean =", mean(array))print("mode =", mode(array))print()print_stats([1, 2, 3, 3, 4])print_stats([1, 2, 3, 3])
# Function to check Armstrong numberdef is_armstrong_number(number):# Convert number to string to iterate over its digitsnum_str = str(number)# Calculate the sum of the cubes of each digitdigit_sum = sum(int(digit) ** len(num_str) for digit in num_str)# Compare the sum with the original numberif digit_sum == number:return Trueelse:return False# Prompt user for a numbernumber = int(input("Enter a number: "))# Check if the number is an Armstrong numberif is_armstrong_number(number):print(number, "is an Armstrong number.")else:print(number, "is not an Armstrong number.")
import calendar# Prompt user for year and monthyear = int(input("Enter the year: "))month = int(input("Enter the month: "))# Create a calendar objectcal = calendar.monthcalendar(year, month)# Display the calendarprint(calendar.month_name[month], year)print("Mon Tue Wed Thu Fri Sat Sun")for week in cal:for day in week:if day == 0:print(" ", end="")else:print(str(day).rjust(2), " ", end="")print()
print(“Hello World”)