Category Archives: Homework

Basic Concepts: Sort3Nums

Classwork:

Preparing for assessment.
1. Trace your program YI_StandarDeviation.py using these numbers: 56, 43, 13, 2, 25
2. Trace your program YI_BasicInstructions4.py ( finding the range ) using these numbers: 3, 21, 65, 88
3. Trace your program YI_Sort3Nums.py using these numbers: 3, 21, 65
4. Trace your program YI_Sort3Nums.py using these numbers: 3, 65, 21
5. Trace your program YI_Sort3Nums.py using these numbers: 21, 65, 3

How to trace:

  1. Drawing a table of code and values as they change.
    trace 1
  2. Writing notes showing the values as they change.
  3. Drawing a diagram with the changes.

Designing an algorithm

Classwork:

Designing an algorithm

Activity:
Work with a partner to design an algorithm: How to draw a picture given a set of instructions.
One student has a blank paper and the other student has a picture that will keep hidden.

Rules of the game:

  1. Don’t let your partner see the drawing.
  2. Your partner will draw the same shape on his/her paper by following your “set of instructions”.
  3. Write down the instructions as you give them.
  4. You can not use direct words that describes the image.
  5. Once finished, both look at the drawings and compare them.
  6. If the drawings don’t match, go back to your instructions and change them until you are satisfied.
  7. You and your partner reverse roles with a different picture though.
  8. Do the instructions need to be revised?

Homework:
Read the following articles linked bellow

Privacy violations – the dark side of social media
Screen Shot 2014-09-04 at 6.12.33 PM

Digital Explosion: Why Is It Happening, and What Is at Stake?
Screen Shot 2014-09-04 at 6.27.26 PM

Find the largest and the smallest in a set of numbers

Click on the Home tab above.

Today’s discussions:
What is python programming language?

What is computer programming? What is an algorithm?

    You need paper and pen/pencil.

  • Work with a partner to do the following activity: Find the largest and the smallest in a set of numbers.
  • Your teacher will hand you a handful of folded papers with a number on each of them.
  • Open only two papers at a time while the rest of them should stayed folded.
  • minmax5

  • Write down the steps or draw a diagram to show how you calculate both numbers.
  • Switch your paper with a different group.
  • Can you follow the steps? Write comments and suggestions about it.
  • Summarize your strategy in one short paragraph in edmodo.com (You can do this part for homework).

Homework:

  1. Send me an email with your parents email address: the email subject should have student name, class period and class name:
    Example:
    Subject: 6th period – Python – Your Name
  2. Discuss the class policy with your parents.
  3. Visit edmodo.com and reply to the “Introduce yourself” post.

Basic: Concepts – CricketTemp_YI.py

Can Crickets Really Tell the Temperature? | Don’t Be Dumb

Classwork:
cricket1
You can tell the current temperature by counting the chirps of a cricket! The formula for calculating the current (Fahrenheit) temperature is:

(Number of Chirps per 60 seconds / 4) + 40

Write a program CricketTemp_YI.py that prompts the user for the number of cricket chirps per 15 seconds and displays the temperature.
Unless you know “loops” you will not be able to do the following) Keep on prompting the user for more input while the response is “y”.

NOTE: Make sure you have a goodbye message when the program ends.

Homework:
Complete the assignment if you have not finished it in class.

Basic: Concepts – Midpoint and more

Classwork/Homework:

  1. Write a program, MidPoint_YI.py that calculates the midpoint between two points on the number line.
    Example: Let’s say x1 = 5 and x2 = 8, the midpoint on the number line is the point 6.5
  2. Write a program, IsItRight_YI.py that determines if the three values given make up the angles of a right triangle.

In all your programs, make sure to include the following:
1. The header
2. A welcome message to the user
3. Be clear when prompting the user
4. Print the results with a message
5. At exit, print a goodbye message.

Homework:
A mortgage calculator program, YI_mortgage.py prompts the user for:
1. The amount to be borrowed
2. The number of years to pay it back
3. The rate charge for borrowing the money
Then prints back what each payment will be. An added feature would be to calculate how much the total amount paid would be at the end of the years the money was borrowed.

This is an example of what a GUI mortgage calculator would look like. You can not implement a GUI at this point but your program can have the same functionality.
MortgageCalc

Formula:
loanPaymentFormula
 

Conditionals: Richter Scale

Classwork/Homework:
Search the internet for the Richter magnitude scale and write a program, RichterScale_YI.py that prompts for the number scale and prints the description of the earthquake intensity: micro, minor, light, moderate, strong, major, and great. Use nested if/else statements.

boolean

9.4. Chaining comparison operators
Comparison operators can be chained. Consider the following examples:

>> x = 2
>> 1 < x < 3
True
>> 10 < x < 20
False
>> 3 > x <= 2
True
>> 2 == x < 4
True
The comparison is performed between each pair of terms to be evaluated. For instance in the first example, 1
The flowchart for the Richter scale program – Use google docs: drawing or draw.io

flowchart-1

lowchartup

Basic: Concepts Content Review

Classwork:
NOTE: Use python shell to confirm your answers for syntax questions


1. Write the code to assign the numerical value 54 to x.
2. Write the code to assign the string 54 to y.
3. What is the difference between questions 1 and 2?
4. What is the code to prompt the user for name and assign it to variable name?
5. Write a code snippet to compare two integer variables x and y. It should display the larger of the two.
6. What is the flowchart shape for a condition?
7. How many arrows point to any one flowchart shape?
8. How many arrows leave a rectangular flowchart shape?
9. Up to how many arrows leave a conditional flowchart shape? Explain your answer.
10. What is the instruction to display a numerical variable age and a string ” years old”?
11. What is the code to prompt the user for a real number amount and assign it to variable amount?
12. Write the python instruction to find the average of the integer variables x1, x2, and x3.
13. Write the python instruction to find the standard deviation of the integer variables x1, x2, and x3. What do you need to import?
Screen Shot 2013-09-17 at 9.13.22 AM
14. What is the result of executing the following python instruction? Explain how python solves the expression.
x = 5 – 2 * 10 + 5
15. How should you write the statement to get 35?
16. What is a boolean variable?
17. Write an instruction to assign the value of pi to variable myPi with relative high precision.
18. Write two different statements to display two variables, one is a integer and the other a string.
19. Given that number is a 4-digit integer, what is it displayed after execution?

x = number % 10
y = number // 10 % 10
z = number // 100 % 10
print (x, " ", y , " ", z)

  1. Can you guess the next one?
  2. What does this code snippet do?
x = int(input("Enter first number "))
y = int(input("Enter second number "))

if x < y:
    t = x
    x = y
    y = t
if x % y == 0:
    print("True")
else:
    print("False")


Homework:

1. Write a python program, YI_TimesTables.py to display a two dimensional table of the product of two numbers from 1 to 10. The output should look like this:

 
  1   2   3   4   5   6   7   8   9  10
  2   4   6   8  10  12  14  16  18  20
  3   6   9  12  15  18  21  24  27  30
  4   8  12  16  20  24  28  32  36  40
  5  10  15  20  25  30  35  40  45  50
  6  12  18  24  30  36  42  48  54  60
  7  14  21  28  35  42  49  56  63  70
  8  16  24  32  40  48  56  64  72  80
  9  18  27  36  45  54  63  72  81  90
 10  20  30  40  50  60  70  80  90 100
>>> 

Format: Output

#f. Output format
12 spaces between the first letter of “Name” and “Grade”

print("Name %12s" % "Grade")
print("123456789012345678901234567890")
>>> 
Name        Grade
123456789012345678901234567890
>>> 

The firs %10s is for “Name” right justified.
The second %10s is for “Grade” also right justified.

print("%10s%10s" % ("Name","Grade"))
print("123456789012345678901234567890")
>>> 
      Name     Grade
123456789012345678901234567890
>>> 

The number 18129.06 has to fit in 10 spaces including the decimal
period, the two decimal digits after the period and right justified.

print("%10.2f" % (400.2 * 45.3))
print("123456789012345678901234567890")
>>> 
  18129.06
123456789012345678901234567890
>>> 

The two floating point numbers has to fit in 10 spaces and right justified.

print("%10.2f%10.2f" % (400.2 * 45.3, 55*123.2))
print("123456789012345678901234567890")
>>> 
  18129.06   6776.00
123456789012345678901234567890
>>> 

Let’s make use of the for loop, the range and the output formatting:

#g. Calculating compound interest

principal = 1000.00  # starting principal
rate = 0.5           # interest rate

print ("Year %21s" % "Amount on deposit:")

## 1234123456789012345678901
## Year    Amount on deposit:

for year in range (1,11):
    amount = principal * ( 1.0 + rate ) ** year # amount = principal * ( 1 + rate )^year
    print ("%4d%21.2f" % (year,amount))         # cool format to display a table 
##   %4d    is for a number of 4 digits for variable year
##   %21.2f is for a number of 21 positions: 18 digits, a decimal period and 2 decimal places

####################################################################################
# %21.2f indicates that variable amount is printed as a float-point value with a 
# decimal point.
# The column has a total field width of 21 character positions and two digits of
# precision to the right of the decimal point; the total field width includes the 
# decimal point and the two digits to its right, hence 18 of the 21 positions appear 
# to the left of the decimal point.
####################################################################################

print("1234123456789012345678.90")

##
##Year    Amount on deposit:
##   1              1500.00
##   2              2250.00
##   3              3375.00
##   4              5062.50
##   5              7593.75
##   6             11390.62
##   7             17085.94
##   8             25628.91
##   9             38443.36
##  10             57665.04
##1234123456789012345678.90


Loops: “for” loop – “range” function

The range function and the for loop
visualizing
The range function:

###################################################################
# Mrs. Elia
# 10/25
# python 3.x
# Description: the range function
#
###################################################################

print ("This program demonstrates how to use the range function from python")

print ("range(10) creates a sequence or list of integers from 0 to 10-1 \n", list(range (10)))


This program demonstrates how to use the range function from python
range(10) creates a sequence or list of integers from 0 to (10-1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

print ("These are both equivalent")
print("range(0,10): ", list(range (0,10)))
print( "and range(0,10,1): ", list(range(0,10,1)))

These are both equivalent
range(0,10): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
and range(0,10,1): [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

The for loop

a. numbers from 1 to 10 in increments of 1

###################################################################
# Mrs. Elia
# 10/25
# python 3.x
# Description: some uses of the for loop
#
#  The for loop
#
###################################################################

for counter in range (1,11):
    print ("value containded in counter is ",counter)   # counter --> 1 2 3 4 ... 10
    

value containded in counter is 1
value containded in counter is 2
value containded in counter is 3
value containded in counter is 4
value containded in counter is 5
value containded in counter is 6
value containded in counter is 7
value containded in counter is 8
value containded in counter is 9
value containded in counter is 10

b. from 10 to 2 in increments of -1 (decrement of 1)

for counter in range (10,1, -1):
    print (counter) # counter takes on the value of each item on the list

c. from 7 to 77 in steps of 7

for counter in range (7,78,7):
    print (counter)  # counter takes on the value of each item on the list

d. Summation

suma = 0
for number in range (1,11):
    suma += number
print ("The sum of all integers from 1 to 10 is ", suma)

The sum of all integers from 1 to 10 is 55

e. Summation

suma = 0
for number in range (2,101,2):
    suma += number
print ("The sum of all even integers from 2 to 100 is ", suma)

The sum of all even integers from 2 to 100 is 2550

Python Data Structures

Assignment: Write a program, factorial_YI.py. Use the “for” loop to calculate the factorial of a given number. Prompt the user for a number. (Look for the post)

Loops: while – random – Roll one Die

More on The Random Module

Screen Shot 2014-10-05 at 12.13.00 PM

Write a program, random_module_YI.py with this short program to understand how random.randrange works.

# Show the randrange range with the "while" loop

import random

i = 0
counter1 = 0
counter8 = 0

print("This program is silently counting the number of times")
print("the numbers 1 and 8 randomly come up with the following ")
print("instruction: randNumber = random.randrange(1,8)") 


while i < 1000:
    i += 1
    randNumber = random.randrange(1,8)
    if randNumber == 1:
            counter1 += 1
    if randNumber == 8:
            counter8 += 1

print("\nThe number 1 showed up ", counter1, " number of times")
print("The number 8 showed up ", counter8, " number of times")


>>> 
This program is silently counting the number of times
the numbers 1 and 8 randomly come up with the following 
instruction: randNumber = random.randrange(1,8)

The number 1 showed up  141  number of times
The number 8 showed up  0  number of times

Answer these questions on the corresponding post:
1. What is needed to import to be able to use the randrange function?
2. What does the body of the loop do?
3. What are the two “arguments” used in randrange?
3. What can you say about the second “argument” in randrange

Assignment:
Write a program, one_die_YI.py that prompts the user how many times to roll a six-sided die and a number on the die. Then it displays how many times the numbers come up.

The output should look like this:

>>> 
User friendly introduction... 

How many times do you want to roll a six-sided die? 500
What number would you like to know how many times it comes up? 3
The number  3  showed up  61  number of times in  500  of rolls

User friendly exit ... 
>>> 

Assignment:
Write a program, one_die_all_YI.py that prompts the user how many times to roll a six-sided die. Then it displays how many times all the numbers come up.
How many times should a die be rolled to validate the theoretical probability for each face to come up?

Loops: Compound Interest

Classwork:
CompoundInterest_YI.py: Use a while loop to calculate how many years it would take to have an accumulated total of at least $1,100 at an interest rate of 1.2% when $1,000 is deposited in a savings bank account.

Homework:
CompoundIntTable_YI.py: Use a while loop to show how the investment increases as the accumulated total becomes at least $1,100 at an interest rate of 1.2% when $1,000 is deposited in a savings bank account.

Welcome to THE INVESTMENT TABLE

year  1  interest for this year  12.0  total accumulated up to this year  1012.0
year  2  interest for this year  24.144000000000005  total accumulated up to this year  1024.144
year  3  interest for this year  36.433727999999974  total accumulated up to this year  1036.433728
year  4  interest for this year  48.870932735999986  total accumulated up to this year  1048.870932736
year  5  interest for this year  61.45738392883209  total accumulated up to this year  1061.457383928832
year  6  interest for this year  74.19487253597799  total accumulated up to this year  1074.194872535978
year  7  interest for this year  87.08521100640974  total accumulated up to this year  1087.0852110064097
year  8  interest for this year  100.13023353848666  total accumulated up to this year  1100.1302335384867

Number of years for the investment of $1000 to reach at least a value of $1,100 with an interest rate of 1.2% is  8

Flowchart 3

Class work:
Make sure you did the following:

  1. Flowcharts for single “if” and uploaded to edmodo.com.
  2. Flowcharts for single “if/else” and uploaded to edmodo.com.
  3. Flowcharts for single “while“. Check your email for a google doc. Upload it to edmodo.com.
  4. Flowcharts for YI_isitRight.py. Upload it to edmodo.com.
  5. Draw your a flowchart from one of your programs.

 

Homework : The “while” with a counter – use the program discussed in class to work on this assignment.

 

Loops: prime_numbers_YI.py

Assignment:
Write a program, prime_numbers_YI.py that prompts the user for an integer and then prints all the prime numbers up to that number. Prime numbers are numbers that are only divisible by itself and the number 1.
Note: 1 is not a prime number
Example: if the user enters 15, the output should look like this

Up to what number would you like to display all prime numbers? 15
All the prime numbers from 2 to 15 are:
2
3
5
7
11
13

screen-shot-2016-10-11-at-1-18-54-pm

Conditionals: Nested if/else structures

Test for multiple cases by placing if/else structures inside other if/else selection structures.
Here is a good example using pseudocode:
Print A for exam grades greater than or equal to 90, B for grades between 80 and 89, C for grades between 70 and 79, D for grades between 60 and 69 and F for all other grades.

if student's grade is greater than or equal to 90
        print "A"
   else
        if student's grade is greater than or equal to 80 
             print "B"
        else
             if student's grade is greater than or equal to 70
                  print "C"
             else
                  if student's grade is greater than or equal to 60
                       print "D"
                  else
                       print "F"

Here is a program snippet:

if grade >= 90:
   print ("A")
else:
   if grade >= 80:
      print ("B")
   else:
   ...

It can also be written in this format:

if grade >= 90:
   print ("A")
elif grade >= 80:
   print ("B")
elif ...

Question:

1. Would the program still work as intended if the symbol >= was changed to <= ???

2. Can I write this program as follows?

if grade >= 90:
   print "A"
if grade >= 80 and grade < 90:
   print "B"
if grade >= 70 and grade < 80:
   print "C"
if ...

3. Can you come up with a different way of writing the program and still in an efficient way?

Here is a flowchart for this structure:

gralNestedIfElseStruct

Here is the starting of the flowchart for the grade assignment:

partialNestedIfElse

Assignments:

  1. Finish the flowchart
  2. Write a program, letter_grade_YI.py. This python program prompts the user for a numeric grade and prints the letter grade.
  3. Write an efficient program, many_letter_grades_YI.py as you discovered in the previous post. This python program prompts the user for a numeric grade and prints the letter grade. Additionally, it continues to prompt the user until the user says “n” to quit.
  4. BEFORE YOU START CODING, DRAW THE FLOWCHART, and don’t start coding until I check it.

Loop: TimesTables.py

1. Write a python program, TimesTables_YI.py to display a two dimensional table of the product of two numbers from 1 to 10. The output should look like this:

 
  1   2   3   4   5   6   7   8   9  10
  2   4   6   8  10  12  14  16  18  20
  3   6   9  12  15  18  21  24  27  30
  4   8  12  16  20  24  28  32  36  40
  5  10  15  20  25  30  35  40  45  50
  6  12  18  24  30  36  42  48  54  60
  7  14  21  28  35  42  49  56  63  70
  8  16  24  32  40  48  56  64  72  80
  9  18  27  36  45  54  63  72  81  90
 10  20  30  40  50  60  70  80  90 100
>>> 

A little challenge:

|   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10
_____ _____ _____ _____ _____ _____ _____ _____ _____ _____
|   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10
|   2 |   4 |   6 |   8 |  10 |  12 |  14 |  16 |  18 |  20
|   3 |   6 |   9 |  12 |  15 |  18 |  21 |  24 |  27 |  30
|   4 |   8 |  12 |  16 |  20 |  24 |  28 |  32 |  36 |  40
|   5 |  10 |  15 |  20 |  25 |  30 |  35 |  40 |  45 |  50
|   6 |  12 |  18 |  24 |  30 |  36 |  42 |  48 |  54 |  60
|   7 |  14 |  21 |  28 |  35 |  42 |  49 |  56 |  63 |  70
|   8 |  16 |  24 |  32 |  40 |  48 |  56 |  64 |  72 |  80
|   9 |  18 |  27 |  36 |  45 |  54 |  63 |  72 |  81 |  90
|  10 |  20 |  30 |  40 |  50 |  60 |  70 |  80 |  90 | 100


Advanced: Computer Number Systems – Part 1

Computer Number Systems – Part 1

NumberSysConvEx
NumberSysConvEx2

NumberSysExercises

Prof. Joseph J. LaViola Number System Resources

Since binary numbers representing moderate values quickly become rather lengthy, bases eight (octal) and sixteen (hexadecimal) are frequently used as short-hand. Octal numbers group binary numbers in bunches of 3 digits and convert the triplet to a single digit between 0 and 7, inclusive.

Some online help on binary numbers

Classwork:Do the rest of the parts for each exercise.

Homework:
Work on Tic Tac Toe project.

Pi Day Activity

Screen Shot 2014-03-13 at 7.53.55 AM
Monday is Pi Day – We will have a pi-day activity ending on Monday
Starting today we are celebrating Pi day by preparing to write a program to do one of the following:
1. Calculate the digits of Pi to highest possible precision
2. Illustrate how Pi is used in a circle.
3. Illustrate how Pi can be applied.
4. Illustrate how Pi was discovered by telling an interactive story.

The programs will be judge based on ingenuity and/or creativity.
NOTE: You can use online resources to help you develop your program. There are good algorithms online. You can not use already written programs.
Include any links used for your resources.

If you like to memorize some of the digits of pi, there will be a competition on Friday. The student who can write the most digits without any help, get a small trophy.

Homework: Explore and investigate the uses and history of pi.
Tomorrow you will tell me what your program you will work on.

Advanced: Computer Number Systems – Part 2


Computer Number Systems – Part 2

All computers – from large mainframes to hand-held micros – ultimately can do one thing: detect whether an electrical signal is “on” or “off”. Computer programs in BASIC and Pascal are converted by various pieces of systems software into sequences of bits (Binary digITs) which correspond to sequences of on/off (equivalently TRUE/FALSE or 1/0) signals. Proficiency in the binary number system is essential to understanding how a computer works.

The Decimal Number System

NumberSysBase10Brk

NumberSysBase10

The Binary Number System

NumberSysBase2Brk

NumberSysBase2

Convert a Binary Number to Decimal Number

NumberSysConv2to10

The Hexadecimal Number System

NumberSysBase16Brk

The Octal Number System

NumberSysBase8

Converting between different Number Systems.

NumberSysConversion

NumberSysConvEx
NumberSysConvEx2

NumberSysExercises

Prof. Joseph J. LaViola Number System Resources

Since binary numbers representing moderate values quickly become rather lengthy, bases eight (octal) and sixteen (hexadecimal) are frequently used as short-hand. Octal numbers group binary numbers in bunches of 3 digits and convert the triplet to a single digit between 0 and 7, inclusive.

NumberSysExercises2

Some online help on binary numbers

Classwork:Do parts a and b for each exercise.

Work on Tic Tac Toe project.

List: Intro


working with lists

Classwork:
Write a new program, ListClwk_YI.py with the work develop in class.
1. Create a list, aList of 100 integers from 1 through 100.

Some tricks you should know:

total = 0
for i in range( len( aList ) ):
   total += aList[i]
print ("the sum of all items in the list is ", total)

total = 0
for item in aList:
   total += item
print ("the sum of all items in the list is ", total)

print ("the sum of all items in the list is ", sum(aList))


2. Create an empty list and adds to the end of the list 100 random integers from 10 to 500
3. Print the list in 10 rows by 10 columns format. Make sure the columns are lined up.
4. Count the number of integers that are even and odd and displays the values with a message.

List: python’s basic concepts in lists


python’s basic concepts in lists
Write a python program list_basics_YI.py

  1. Creating a list.
  2. add elements to a list
  3. access a list’s values by iteration
  4. access a list’s values by index
  5. modify elements in a list
  6. add all elements in a list
  7. assign 100 random integer numbers between 1 and 100 to a new empty list, new_list
# 1. Creating a list.

a_list = []    # create empty list

# 2. add elements to a list
for number in range( 1, 11 ):
   a_list += [ number ]

print ("The values of a_list are:", a_list )  

# 3. access a list's values by iteration
print ("\nAccessing values by iteration:")

for item in a_list:
   print (item,end='')
print("\n")

# 4. access a list's values by index
print ("\nAccessing values by index:")
print ("Subscript   Value")

for i in range( len( a_list ) ):
   print ("%9d %7d" % ( i, a_list[ i ] ))

# 5. modify elements in a list
print ("\nModifying a list value...")
print ("Value of aList before modification:", a_list)
a_list[ 0 ] = -100   
a_list[ -3 ] = 19
print ("Value of aList after modification:", a_list)

# 6. add all elements in a list
total = 0
for i in range( len( a_list ) ):
   total += a_list[i]
print ("the sum of all items in the list is ", total)


# 7. assign random integer numbers between 1 and 100 to a new empty list, new_list

Required Submission
1. Copy and paste the programs in the Text Entry tab.
2. Submit the list_basics_YI.py or the repl.it link.
NOTE: Documentation
Header:

a) Assignment description ( you can copy and paste the assignment itself)
b) Author’s name
c) Language and version
d) Date of completion
Input/Output:
Input(If any) and output for each part.

List: Tutorial on list(range(10))

Lists:



More on for-loops and review of previous assignments.

>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> list(range(0, -10, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> list(range(0))
[]
>>> list(range(1, 0))

Assignments:
Write code snippets for the following specific sequence of integers using the range function:
NOTE: the lower and upper bounds are included in the lists.
a. A list of even integer numbers from 2 through 24.
b. A list of even integer numbers from 48 through 22.
c. A list of perfect square numbers from 1 through 100.
d. A list of numbers starting from -13 through 0.

Required Submission
Copy and paste the snippets and the output in the Text Entry tab.

NOTE: No need for documentation.

Functions: Say Hello

Complete this assignment.

 

###################################################################
# Description: improve this program by using functions 
# Mrs. Elia
# 10/7
# python 3.9
#
###################################################################
aName = input("Hi! What is your name? ")
print "Hello ",aName, "! I hope you are enjoying your day!"

##>>> 
##Hi! What is your name? grace
##Hello grace! I hope you are enjoying your day!
##>>> 

Here is an outline of the changes:

#from
aName = input("Hi! What is your name? ")
print "Hello ",aName, "! I hope you are enjoying your day!"

# to functional programming
def hello(aName): # it prompts the user for a name
                  # it prints a message with the name

def main():       # it calls the only one function

main()  # execute by calling it

Read this article: Fostering Tech Talents in School. All of it.

Functions: Visualization

Classwork:

function_machines_composed_combined_mod
You will be drawing a sketch like this one
visualizing-functions
1. Draw a visualization for the Circle_Calulations_YI.py
2. Draw a visualization for the following assignment:

Write a program, Alge_Calc_WFunctions_YI.py to simulate a 4-function calculator.
Follow these guidelines:
a. Define dataInput function to prompt the user for two integer numbers and passes them to the other functions. Here is the syntax to pass more than one parameter: return [num1,num2]
b. Define function menu:

  1. Add
  2. Subtract
  3. Multiply
  4. divide

c. Define a function for each operation
def add(nums):

def subtract(nums):

def multiply(nums):

def divide(nums):

d. main should look like this:

Welcome to "My Python Calculator"
Would you like to 
1. Add
2. Subtract
3. Multiply
4. Divide
Select your option by entering the number 1

Enter a number 4
Enter another number 9
The sum of 4 and 9 is 13
Would you like to do another operation?  y/n 

Functions: Temperature Functions

Classwork/Homework:

Implement the following function fahrenheit to return the Fahrenheit equivalent of a Celsius temperature.

   F = (9/5) * C + 32

Use this function to write a program, TemperatureTables_YI.py that prints a chart showing the Fahrenheit equivalents of all Celsius temperature 0-100 degrees. Use one position of precision to the right of the decimal point for the results. Use the “%” to format your output properly.

Add a function celsius to return the Celsius equivalent of a Farenheit temperature.

    C = (5/9) * ( F – 32 )

Just like the previous function, print a chart with the Celsius equivalents of all Fahrenheit temperature 0-100 degrees. Use one position of precision to the right of the decimal point for the results. Use the “%” to format your output properly. The program should start with a menu to choose which temperature’s table the user wants to select
Welcome to Farenheit-Celsius Tables
Pres 1 for Farenheit 2 for Celsius and 3 to exit.