-
Notifications
You must be signed in to change notification settings - Fork 0
/
ass- 9.py
116 lines (57 loc) · 1.52 KB
/
ass- 9.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
# coding: utf-8
# Sets in python.
#
# unordered collection of elements using{}.
#
# maintains uniqueness of elements
#
# doesnt support indexing for acessing element
#
# does supports mathematical sets operation(union,intersection,diff. and symmetry.
#
# In[3]:
names={'Ali','Naimat','Fahad'}
unique_names =set(names)
unique_names.add('hadi')
unique_names.remove('hadi')
print(unique_names)
# In[1]:
num1 = {1,2,3,4,4,5,6,7,8,9}
num2 = {1,3,4,5,6,7,8,1}
print(num1 | num2)
print(num1 & num2)
print(num1 - num2)
print(num1 ^ num2)
# Functions in python
# In[1]:
def greet(f_name,last_name):
print(f"hi there {f_name} {last_name}")
greet(Ali,hasnat)
# In[4]:
def increment(num,by):
return num*by
increment(2,by=5)
# In[24]:
#secret msg (aka cypher) and encoded msg
def cypher(message,shift):
encrypted_msg= ""
for char in message:
if char.isalpha():
alphabets='abdcdefghijklmnopqrstuvwxyz'
if char.isupper():
alphabets="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
position= alphabets.find(char)
shifted_position = (position+shift)%26
encrypted_chr =alphabets[shifted_position]
encrypted_msg += encrypted_chr
else:
encrypted_msg +=char
return encrypted_msg
message =input("Enter your message")
shift=int(input("by how many char ou wants to shift your charcater"))
print(cypher(message, shift))
# In[ ]:
# Dictonaries converter
# In[ ]:
#Weigth conerter
def weigth(mass)