-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSIGNMENT 5.txt
147 lines (104 loc) · 4.08 KB
/
ASSIGNMENT 5.txt
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
#ASSIGNMENT 5
#Write a function named sort_odd_even() that will sort a list of numbers with the odd numbers
#coming first and the even numbers coming second. You can use the list.sort function.
'''def num(l,e,o):
for i in range (4):
l.append(int(input("enter the number")))
for j in l:
if j%2==0:
e.append(j)
e.sort()
else:
o.append(j)
o.sort()
print(o+e)
return num
l=[]
e=[]
o=[]
num(l,e,o)'''
#By using list comprehension, write a program to print the list after removing the value 24 in [12,24,35,24,88,120,155]
'''l=[12,24,35,24,88,120,155]
print([x for x in l if x!=24 ])'''
#Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers.
'''a=input("enter the elements in a list separated by comma")
newlist=[int(x)**2 for x in a.split(",") if int(x)%2!=0]
print(newlist)'''
#Using list comprehension, return the number of even integers in the given array.
'''n=[1,2,3,4,5,6,7,8,9,10]
e=[i for i in n if i%2==0]
print(e)'''
#Use filter() to eliminate all words that are shorter than 4 letters from a list of words.
''def remove_words(list1):
result=list(filter(lambda s:len(s)>3,list1))
print(result)
list1=["hello","world","iam"]
remove_words(list1)'''
'''l=[x for x in input("enter the words").split(" ")]
def shorter(y):
if len(y)>3:
return True
return False
x=filter(shorter,l)
print(list(x))'''
#Write a list comprehension statement to convert a list of Fahrenheit temperatures to Celsius
'''n=[100,200,50,300]
f=[(i-32)*5/9 for i in n]
print(f)'''
#Use map and a lambda function to convert a list of Fahrenheit temperatures to a list of Celsius temperatures
'''t=[100,200,300]
m=list(map(lambda n: 5/9*(n-32),t))
print(m)'''
#Input two lists and convert the two list to dictionary.
'''a=input("enter the keys")
b=input("enter the values")
l1=a.split(",")
l2=b.split(",")
d=dict(zip(l1,l2))
print(d)'''
#Make a two-player Rock-Paper-Scissors game. One of the players is the computer. 10 chances.
#Print out the winner and points earned by both players.
'''import random
pWin=0
cWin=0
tieCount=0
for playcount in range(1,11):
playerInput=input("Enetr R for Rock,P for Paper.S for Sicor:")
randomNumber= random.randint(0, 2)
computerInput=(['R','S','P'])[randomNumber]
print('you have entered : ',playerInput)
print('computerInput : ',computerInput)
if((playerInput=='R' and computerInput=='R') or (playerInput=='S' and computerInput=='S') or (playerInput=='P' and computerInput=='P')):
print( "tie")
tieCount=tieCount+1
elif ((playerInput == 'R' and computerInput == 'S') or
(playerInput == 'S' and computerInput == 'P') or (playerInput == 'P' and computerInput == 'R')):
pWin=pWin+1
print("You win")
else:
computerWinCount=computerWinCount+1
print("computer won")
print(pWin," is player win count and " ,cWin," is computer win count. ",tieCount," games tie")
#Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
'''c=input("enter the number")
d=c.split(",")
print(d)
print(tuple(d))'''
#Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
'''a=input("enter the words")
c=a.split(",")
c.sort()
print(c)'''
#Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not.
# The numbers that are divisible by 5 are to be printed in a comma separated sequence.
'''a=input("enter the 4 digit binary numbers with, separated")
value=[]
#items=[x for x in a.split(",")]
items=a.split(",")
for p in items:
decimal=int(p,2)
print(decimal)
if decimal%5==0:
value.append(p)
print(value)
print(",".join(value))'''