-
Notifications
You must be signed in to change notification settings - Fork 0
/
PracticeFuncs.py
186 lines (167 loc) · 5.19 KB
/
PracticeFuncs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import random
import datetime
import string
def Divisors():
divide = int(input("Enter the number you want the divisors of: "))
numbers = range(1, divide + 1)
for num in numbers:
if divide % num == 0:
print(num)
def FibonacciGen( num ):
nums = [1, 1]
if num == 1:
return 1
elif num == 2:
return nums
else:
for i in range(1, num-1):
nums.append(nums[i] + nums[i-1])
return nums
def evenList(numbers):
newList = [x for x in numbers if x % 2 == 0]
return newList
def getListEnds( list ):
newList = [list[0], list[len(list)-1]]
return newList
def listLess(a_list):
newList = [num for num in a_list if num < 5]
if input("Would you like to find all numbers less than a specific number?(y/n): ") == "y":
limit = int(input("Enter that number: "))
newList = [num for num in a_list if num < limit]
return newList
def ListOverlap(list1, list2):
newList = list((set(list1).intersection(set(list2))))
return newList
def randList(length, num):
yourList = []
for i in range(length):
yourList.append(random.randint(0, num))
return yourList
def max_of_three(numberList):
highest = 0
for num in numberList:
if num > highest:
highest = num
return highest
def NumGuess():
secretNum = random.randint(1, 9)
userInput = ""
guesses = 0
while userInput != "exit":
userInput = input("Guess a number between 1 and 9: ")
userInput = int(userInput)
guesses += 1
if userInput == secretNum:
print("Correct! It took you %d guesses" % (guesses))
break
elif userInput > secretNum:
print("Your answer was too high!")
else:
print("Your answer was too low")
def evenorodd():
try:
number = int(input("Please enter a number to check: "))
divide = int(input("Please enter a number to divide by: "))
if number % divide == 0:
return "%d goes evenly into %d" % (number, divide)
elif number % 4 == 0:
return "this number is a multiple of 4"
elif number % 2 == 0:
return "%d is even" % (number)
elif number % 2 != 0:
return "%d is odd" % (number)
else:
return "I don't know"
except ValueError:
print("You did not enter a number")
evenorodd()
def median(items):
medianNum = 0
items = sorted(items)
print(items)
if len(items) % 2 == 0:
half = int(len(items)/2)
print(half)
one = items[half]
print(one)
two = items[half - 1]
print(two)
medianNum = (float(one + two))/2.0
else:
medianNum = items[len(items)/2]
return medianNum
def RockPaperScissors():
winner = False
nameOne = input("What is the first player's name?: ")
nameTwo = input("What is the second player's name?: ")
playOne = ""
playTwo = ""
while winner != True:
playOne = input("Enter rock, paper, or scissors: ")
playTwo = input("Enter rock, paper, or scissors: ")
if Compare(playOne, playTwo) == "one":
winner = True
print("Player one is the winner")
elif Compare(playOne, playTwo) == "tie":
print("There was no winner")
elif Compare(playOne, playTwo) == "two":
winner = True
print("Player two is the winner")
else:
print("You done messed up")
def Compare(one, two):
if one == "rock" and two == "scissors":
return "one"
elif one == two:
return "tie"
elif one == "scissors" and two == "paper":
return "one"
elif one == "paper" and two == "rock":
return "one"
else:
return "two"
def Palindrome():
words = input("Please enter a string: ")
if words == words[::-1]:
return True
else:
return False
def turn100():
name = input("Please enter your name: ")
now = datetime.datetime.now()
cien_year = 0
print_num = 1
age = int(input("Please enter your age: "))
print_num = int(input("Enter another number: "))
cien_year = now.year + (100-age)
for i in range(print_num):
print("%s will turn 100 in the year %d" % (name, cien_year))
def remDupSets( items ):
new_list = set(items)
items = list(new_list)
return items
def remDupOther( items ):
new_items = []
for i in range(0, len(items)):
if items[i] not in new_items:
new_items.append(items[i])
return new_items
def reverseSentence( words ):
all_words = words.split()
all_words = all_words[::-1]
return " ".join(all_words)
def passwordGen( length ):
password = []
symbols = ['!', '?', "@", '_', '-', '/', '(', ')']
letters = []
for item in string.ascii_letters:
letters.append(item)
for i in range(length):
listNum = random.randint(0, 3)
if listNum == 1:
password.append(symbols[random.randint(0, len(symbols) - 1)])
elif listNum == 2:
password.append(letters[random.randint(0, len(letters) - 1)])
elif listNum == 0:
password.append(str(random.randint(0, 9)))
return "".join(password)