|
1 | 1 |
|
2 | 2 | #######################################################################################################
|
3 |
| -# Conditionals - Lab Exercise 4 |
| 3 | +# Conditionals - Lab Exercise 5 |
4 | 4 | #
|
5 | 5 | # Use the variable x as you write this program. x will represent a string.
|
6 |
| -# Write a program using the elif keyword that determines if x is a primary color (red, blue, or yellow). |
7 |
| -# If yes, print _ is primary color, where the blank is the value of x. |
8 |
| -# If no, print _ is not a primary color, where the blank is the value of x. |
| 6 | +# Write a program that determines if x is a vowel (a, e, i, o, and u ). |
| 7 | +# If yes, print _ is a vowel, where the blank is the value of x. |
| 8 | +# If no, print _ is not a vowel, where the blank is the value of x. |
9 | 9 | #
|
10 | 10 | # Expected Output:
|
11 |
| -# If x is red, then the output would be: red is a primary color. |
12 |
| -# If x is teal, then the output would be: teal is not a primary color. |
| 11 | +# If x is a, then the output would be: a is a vowel. |
| 12 | +# If x is z, then the output would be: z is not a vowel. |
13 | 13 | #
|
14 | 14 | #######################################################################################################
|
15 | 15 |
|
16 |
| -x='blue' |
17 |
| -if x == "red": |
18 |
| - print("x is red is a primary color") |
19 |
| -elif x == "blue": |
20 |
| - print("blue is a primary color") |
21 |
| -elif x == "yellow": |
22 |
| - print("yellow is a primary color") |
| 16 | +x='a' |
| 17 | +if x in 'aeiouAEIOU': |
| 18 | + print(x, "is a vowel") |
| 19 | +else: |
| 20 | + print(x, "is not a vowel") |
23 | 21 |
|
24 |
| -# Output => blue is a primary color |
| 22 | +# Output => a is a vowel |
| 23 | + |
| 24 | +x='z' |
| 25 | +if x in 'aeiouAEIOU': |
| 26 | + print(x, "is a vowel") |
| 27 | +else: |
| 28 | + print(x, "is not a vowel") |
| 29 | + |
| 30 | +# Output => z is not a vowel |
| 31 | + |
| 32 | +####################################################################################################################### |
| 33 | +# ALTERNATIVE SOLUTION: |
| 34 | +####################################################################################################################### |
| 35 | + |
| 36 | +x='a' |
| 37 | +if x == "a" or x == "e" or x =="i" or x == "o" or x == "u" or x == "A" or x == "E" or x =="I" or x == "O" or x == "U": |
| 38 | + print(x + " is a vowel") |
| 39 | +else: |
| 40 | + print(x + " is not a vowel") |
| 41 | + |
| 42 | +# Output => a is a vowel |
0 commit comments