-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadv_tuple_topics.py
More file actions
65 lines (51 loc) · 1.76 KB
/
adv_tuple_topics.py
File metadata and controls
65 lines (51 loc) · 1.76 KB
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
# adv_tuple_topics
# more tuple topics needed for programming labs
# shows use of multiple data types in a tuple(str,int)
# also shows comparison of values
#1 adding multiple variable types to a tuple
# (can use for or while loop, shown with for here)
# initialize variables
s_name = ""
s_grade = 0
s_tuple = ()
fail_tuple = ()
s_len_max = 0
s_grade_max = 0
long_name = ""
num_fail = 0
# CONSTANT: a variable that contains an unchanging value (capitalized)
VOWELS = "aeiou"
vowel_count = 0
for i in range(4):
s_name = input("\nWhat is the student's name? ")
s_grade = int(input("What is their grade? 0-100: "))
s_tuple +=((s_name, s_grade),)
print(s_tuple)
#2 finding number of vowels in name
vowel_count = 0
for i in s_name:
if i in VOWELS:
vowel_count += 1
print("\nThere are", vowel_count, "vowel(s) in" , s_name)
#3 comparing len of student names to find the longest name
if len(s_name) > s_len_max:
s_len_max = len(s_name)
long_name = s_name
print ("\nThe longest name is: ", long_name,
"and it is" , s_len_max , "letters long.")
#4 comparing student scores to find highest score
if s_grade > s_grade_max:
s_grade_max = s_grade
print ("The highest grade is: ", s_grade_max)
print("\nThis is the s_tuple in tuple format: ", s_tuple)
#5 looping through tuple to find students who are failing
input("\nPress enter to find failing students: ")
for i in s_tuple:
if i[1] < 60:
num_fail += 1
fail_tuple += (i[0],)
print("\nThe number of students who are failing is: ", num_fail)
print("The failing students are:")
for i in fail_tuple:
print(i)
input("\nPress enter to exit.")