-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
82 lines (70 loc) · 1.78 KB
/
functions.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
"""
Introduction to functions
"""
# Multiplies two numbers
def multiply (n, m):
return n * m
a = 5
b = 6
c = multiply(a, b)
print(c)
# Performs arithmetic expressions on the value n
x = int(input("Enter a number [1 - 100] :"))
def dosomething (n):
n = n * 2
n = n ** 3
n = n/5
return n
if x < 1 or x > 100:
print("Enter a number between 1 - 100")
else:
print(dosomething(x))
# Encryter
def noVowels (message):
vowels = "aeiou"
secret = ""
for letter in message:
if not letter in vowels:
secret = secret + letter
return secret
your_message = input("Enter message: ")
print("Your secret message is", noVowels(your_message))
# Changes two letters to uppercase
def changeCase(s):
new_s = ""
for letter in s:
if letter.islower():
new_s = new_s + letter.upper()
else:
new_s = new_s + letter.lower()
return new_s
message = "One Two"
print(changeCase(message))
# Runs repeatedly until the user enters a valid interger.
def getValidInterger (prompt, lower, upper):
while True:
number = int(input(prompt))
if number < lower or number > upper:
print("Error the number must range from" + str(lower) + "through" + str(upper))
else:
return number
# Encrypter version two
def encrypt(source):
code = ""
for ch in source:
code = code + str(ord(ch)) + " "
return code
message = input("Enter message")
secret = encrypt(message)
print(secret)
# Decrypter
def decrypter(code):
source = ""
for word in code.split():
source = source + chr(int(word))
return source
message = input("Enter your messsage: ")
secret = encrypt(message)
print("Secret message:", secret)
print()
print("Original message:", decrypter(secret))