Question: Activity 4: Please copy the following program into a file called sign py and run it a few times, cntering different numbers (positive, negative, and


Activity 4: Please copy the following program into a file called sign py and run it a few times, cntering different numbers (positive, negative, and zero) cach time "How does this affect the output of your program when you enter various values? number floatfinput Enter a number:")) if number0 number is What is the output if you enter a positive number? If all went well, you should have discovered that when python cncounters an if statement it checks whetlher the associated condition in this case, number0) is true. If it is, python executes all statements that immediately follow the if clause and are indented bencath it. If the condition is false, thse statements are skipped. In either case, execution will then continue with the next un-indemed statement Notice in partieular that to ask whether one value "equals" another value, you must use o equals sigas, not one. For example, we could say: What is the output if you enter a negative number? (Enter a number:) number oatinpuf if number 0 You entered 0. What is the output if you enter a zero? The if statement and relational operators work for comparing strings just like they do for comparing numbers Activity 5: Write a program called tavorite.py that asks the user to eater a color nane. If the color entered happens to be your favorite color, print a message We have the same favorite color!". Otherwise, do not print any response. (Be very careful with punctuation in this program. The if clause must end with a colon, or python will complain.) Now add a sccond print statement (with any message you want) at the end of the program, being careful to indent it by the same amount the first print statement is indented. copy and paste your favoritepy here copy and paste your code here How does this affect the output of your program when you enter various valucs? Now try removing the indentation from the second print statement. In other words, leave the first print statement where it is, but move the second oee back to be aligned with the it) Notice that to check wbether your program entering colors that test both outcomes. works corectly, you will now have to run it at least twice, copy and paste your code here: Now add one statement to your program that will cause it to print "Goodbye just before it ends, regardless of the color entered. Obviously, you also want to test your program to make sure it works
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
