-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_12.py
More file actions
44 lines (27 loc) · 937 Bytes
/
05_12.py
File metadata and controls
44 lines (27 loc) · 937 Bytes
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
'''
Count occurrences of a character in a word
Python Practice
05_12.py
'''
inputstr = input('Enter a string:')
char = input('Enter the character to count:')
count = inputstr.lower().count(char.lower())
print(f'Character {char} occurs {count} times')
print(f'ASCII of Character {char} is {ord(char)}')
sentence = input('Enter a sentence:')
words = sentence.split()
max_length = 0
longestW = ""
for i in words:
if len(i) > max_length:
longestW = i
print(f'Longest word is {longestW}')
list_1 = input('Enter 1st list of numbers:').split()
list_2 = input('Enter 2nd list of numbers:').split()
commonlist = list(set(list_1) & set(list_2))
print(f'Common elements are:{commonlist}')
nums = [float(x) for x in input('Enter list of numbers with spaces:').split()]
ascending = sorted(nums)
descending = sorted(nums, reverse = True)
print(f'Numbers in order: {ascending}')
print(f'Numbers in reversed: {descending}')