Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- """
- # 1)
- Define a function MaxOfThree() that takes three numbers as arguments
- and returns the largest of them (Use If, elif and else).
- For example, MaxOfThree(1, 2, 3) should return 3
- def MaxOfThree(x1, x2, x3):
- if (type(x1) == int and type(x2) == int and type(x3) == int):
- if(x1 > x2 and x1> x3):
- return x1
- elif(x2 > x1 and x2> x3):
- return x2
- else:
- return x3
- else:
- print("Dambass, input numbers only!")
- print(MaxOfThree(1,"2",3))
- # 2)
- Define a function MySum() and a function MyMultiply() that sums
- and multiplies (respectively) all the numbers in a list of
- numbers (Use for). For example, s MySum([1, 2, 3, 4]) should return 10,
- and MyMultiply([1, 2, 3, 4]) should return 24.
- n = range(1, 6)
- def MySum(list1):
- sum =0
- for l in list1:
- sum += l
- return sum
- def MyMultiply(list2):
- mult = 1
- for l in list2:
- mult *= l
- return mult
- print(MySum(n))
- print(MyMultiply(n))
- # 3)
- Define a function MyMean() that receives an unknown amount
- of input values from a user and returns the mean value of all the
- input values (Use while). For example: if the user provides [1, 2, 3, 4],
- the MyMean(), should return 2.5
- def MyMean(l):
- print(np.mean(l))
- final = []
- while True:
- means = input('Please enter a number: ')
- if not means:
- break
- final.append(int(means))
- MyMean(final)
- Define a function MyStars() that takes a list of integers and prints
- a string of stars which has the length of a value of an integer to
- the screen. For example, MyStars([3, 9, 7]) should print the following:
- ***
- *********
- *******
- numbers = []
- while True:
- means = input('Please enter a number: ')
- if not means:
- break
- numbers.append(int(means))
- def MyStars(l):
- for i in l:
- print("*"*i)
- MyStars(numbers)
- # 5)
- Define a function SecondBest() that receives a list of numbers and
- returns the second largest and second smallest numbers. For example,
- SecondBest([1, 2, 3, 4]) should return [3, 2] (do not use built in
- functions such as max or sort).
- best_list = []
- while True:
- means = input('Please enter a number: ')
- if not means:
- break
- best_list.append(int(means))
- def SecondBest(best_list):
- if best_list[0] > best_list[1]:
- first_max = best_list[0]
- first_min = best_list[1]
- else:
- first_max = best_list[1]
- first_min = best_list[0]
- second_min = first_max
- second_max = first_min
- for i in range(2, len(best_list)):
- if best_list[i] > first_max:
- second_max = first_max
- first_max = best_list[i]
- elif best_list[i] < first_min:
- second_min = first_min
- first_min = best_list[i]
- return second_min, second_max
- x, y = SecondBest(best_list)
- print("Second largest number is " + str(y))
- print("Second smallest number is " + str(x))
- """
- #6)
- letters = []
- while True:
- input_l = input('Please enter a letter: ')
- if not input_l:
- break
- letters.append(input_l)
- def MySort(char_list):
- sorted_l = [range(ord("a"), ord("z"))]
- for i in char_list:
- sorted_l[chr(ord(i))] += 1
- for j in sorted_l:
- while j>0:
- char_list.append(chr(ord("a")+j))
- j -= 1
- return char_list
- print(MySort(letters))
Add Comment
Please, Sign In to add comment