CIS 6 : Lab 01 – Introduction to Python
python语言代写 Instructions: Briefly answer the questions below.KeywordsCompiler:Interpreter:Integrated Development Environment:IDLE:List two differences···
Task 1: Definitions & Concepts python语言代写
Instructions: Briefly answer the questions below.
- Keywords
- Compiler:
- Interpreter:
- Integrated Development Environment:
- IDLE:
- List two differences between Compiling and Interpreting:
A compiler is no longer needed after a program is translated |
- Write a detailed step-by-step algorithm for making a peanut butter and jelly sandwich (or some other everyday activity) (10 steps max):
a) |
Task 2: Understanding Programming python语言代写
Instructions: Answer each question below. Try to understand and explain the code. Use an IDLE shell to test if you need to.
Test 1: [Hit Enter after each line. Observe what gets printed]
>>> print (“Hello, world!”)
Hello, world! |
>>> print (“Hello” , “world!”)
‘Hello’, ‘world!’ |
>>> print (3)
3 |
>>> print(“2+3=”, 2+3)
‘2+3=’, 5 |
>>> print (“Hello, world!”)
‘Hello, world!’ |
>>> print (“Hello” , “world!”)
‘Hello’, ‘world!’ |
>>> print (3)
3 |
>>> print(3.0)
3.0 |
>>> print (2 + 3)
5 |
>>> print(2.0 + 3.0) python语言代写
5.0 |
>>> print (“2” + “3”)
’23’ |
>>> print (“2 + 3 =” , 2 + 3)
‘2 + 3 =’, 5 |
>>> print (2 * 3)
6 |
>>> print (2 ** 3)
8 |
>>> print (2 / 3)
0.6666666666666666 |
Test 2: Define function and call it to run.
>>> def hello():
print(“Hello”)
print(“Computers are fun”)
[Hit Enter twice]
>>> hello()
- Explain what happens:
Hello
Computers are fun |
Test 3: Define a function with a parameter. python语言代写
>>> def greet(person):
print(“Hello, “, person)
print(“How are you?”)
[Hit Enter twice]
>>> greet(“Mr. Ortak”)
>>> greet(“[your name]”)
- Explain what happens
Hello, Mr. Ortak
How are you? |
Test 4: >>> x = input(“Enter a number: “) python语言代写
- then enter a number
- then enter x * 9
- Explain what happens
Test 5: >>> x = input(“Enter a number: “)
- then enter any letter or symbol
- then enter x * 9
- Explain what happens
Test 6: >>> x = int(input(“Enter a number: “))
- then enter a number
- then enter x * 9
- Explain what happens
Test 7: x = int(input(“Enter a number: “))
- then 9.0
- Explain what happens
- e) x = eval(input(“Enter a number: “))
- then enter a number 9.0
- then enter x * 9
- Explain what happens
Task 3: TextBook programming exercises python语言代写
Instructions: The textbook has some chapter-end programming exercises. Go to page 24 -25 of the book and do the exercises below and put the screenshots of your code and test run here. Make sure to keep a separate copy of each file. Your screenshots must be legible.
Exercise 3: Modify the Chaos program using 2.0 in place of 3.9 as the multiplier in the logistic function. Your modified line of code should look like this: x = 2.0 * x * (1 – x)
Run the program with various input values and compare the results to those obtained from the original program. Write one sentence describing any differences that you notice in the behavior of the two versions.
Exercise 4: Modify the Chaos program so that it prints out 20 values instead of 10.
Exercise 5: Modify the Chaos program so that the number of values to print is determined by the user. You will have to add a line near the top of the program to get another value from the user: n = eval(input(“How many numbers should I print? “))
Then, you will need to change the loop to use instead of a specific number. python语言代写
Exercise 6: The calculation performed in the chaos program can be written in a number of ways that are algebraically equivalent. Write a version of the chaos program for each of the following ways of doing the computation. Have your modified programs print out 10 iterations of the function and compare the results when run on the same input.
- 9 * x * (1 – x)
- 9 * (x – x * x)
- 9 * x – 3.9 * x * x
Explain the results of this experiment:
Exercise 7: Modify the Chaos program so that it accepts two inputs and then prints a table with two columns similar to the one shown in Section 1.8. (Note: You will probably not be able to get the columns to line up as nicely as those in the example. Chapter 5 discusses how to print numbers with a fixed number of decimal places.)
Think Python Book Exercises python语言代写
(No submission) Exercise 1: Start the Python interpreter and type help() to start the online help utility. Or you can type help(‘print’) to get information about the print statement.
(No submission) Exercise 2: Start the Python interpreter and use it as a calculator. Python’s syntax for math operations is almost the same as standard mathematical notation. For example, the symbols +, – and / denote addition, subtraction and division, as you would expect. The symbol for multiplication is *.
Task 4: TextBook programming exercises
Instructions: Write a program asking users for their birth year (e.g. 1995) and prints how old they are (e.g. “You are 26 years old.”). Share a screenshot of your code and test run.