Question

In: Computer Science

The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...

The Objectives are to:

  1. Use IDLE IDE for Python.
  2. Develop a few simple Python programs and show they will translate and run.
  3. Experience error messages when you enter bad syntax the interpreter cannot understand.

Discussion:

The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you get. Finally, you will be given a "specification" of a simple problem to solve. From this specification create a program, and run it against a set of specified test values. Properly document the last program so another person can read it and determine its purpose.

Specifications:

1.  Using IDLE IDE to create a source code file named welcome.py, enter the following Python code, translate it and run it.

def main():

    print("Welcome to the wonderful world of Python programming!")

main()

After a successful run, capture its output and close its workspace.

2.   Perform the same steps described in part 1 for the following program:

def main():

    integer1 = int(input("Enter first integer"))     # prompt and enter the first integer

    integer2 = int(input("Enter second integer"))    # prompt and enter the second integer

    sum =    integer1 + integer2                     # generate and assign the sum

    print("The sum of", integer1, "and", integer2,

"is", sum)                                     # print sum

    difference = integer1 – integer2                # assignment of difference

    print("The difference of", integer1, "minus",

integer2, "is", difference)                    # print difference

main()

3. "Comment-out" the second line of the second program so it looks like this:

          # integer1 = int(input("Enter first integer"))     # prompt for and input first integer

Try to run the modified program and record (and hand in) the error message(s).

4. Remove the comment symbol from the previous part (i.e., restore your program to

its previous working condition) and then comment-out the sum assignment statement like this:

                  # sum =    integer1 + integer2                            # assignment of sum

           

            Run the modified program and capture the error message(s) you see.

5. Restore your working program again and then comment-out the code line,

                        # difference = integer1 – integer2                 # assignment of difference

Once again run the modified program and capture the error message(s) you see. Explain why the error message you got when commenting out the sum statement differs than when commenting out the difference statement.

  6.  Problem:  Design, Develop, Integrate, and Test (DDI&T) a Python program that converts a Fahrenheit temperature into its Celsius temperature equivalent.

          

             The formula for converting Fahrenheit to Celsius is,

                        Celsius = 5.0/9.0*(Fahrenheit – 32.0)

Your program should prompt the user for a Fahrenheit temperature, convert it to Celsius and then output both values in the following format:

         Fahrenheit Temperature = <Fahrenheit value>

         Celsius Temperature = <Celsius value>

            Fully test your program with the following set of Fahrenheit temperatures:

         75.5, 32.0, -459.4, -40.0, 0.0, 100.0, and 212.0

Note that the temperature values are both input and output with one decimal of precision after the decimal point.

           

Documentation Guidelines:

Use good programming style (e.g., indentation for readability) and document each of your program parts with the following items (the items shown between the '<' and '>' angle brackets are only placeholders. You should replace the placeholders and the comments between them with your specific information). Your cover sheet should have some of the same information, but what follows should be at the top of each program's sheet of source code. Some lines of code should have an explanation of what is to be accomplished, this will allow someone supporting your code years later to comprehend your purpose. Be brief and to the point. Start your design by writing comment lines of pseudocode. Once that is complete, begin adding executable lines. Finally run and test your program.

    

#===================================================================

#    CS119T – Unit 1-Submission NodeIDEs and Debugging

#    Filename: Unit 1 Submission Node: my-unit1-submission-node.doc

#    Author: <Your name>

#    Purpose: Demonstrate basic Python programming in the IDLE

#               development environment

#               by following steps 1 through 6 above.

#===================================================================

Deliverable(s):

Your deliverable should be a Word document with screenshots showing the code you have created, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them for all of the programs listed above as well as the inputs and outputs from running them. For parts 3, 4 and 5 where you deliberately "seeded" errors into your code, capture and turn in the error messages you encountered when attempting to translate and run these errant programs.  Include a cover sheet with the hardcopy of your labs when you turn them in to the instructor.

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

welcome.py :

def main(): #function
#print message
print("Welcome to the wonderful world of Python programming!")

main() #function call
=========================

Output :

screen 1:welcome.py

************************

Question 2 :

=================

Output :

******************************

Question 3 :Error message screen

**************************

Question 4 :

***********************************

Question 5 :

Explanation :

  • sum = integer1 + integer2
  • when above line is commented even though getting output because here sum is inbuilt function in python that is considered.
  • But in case on difference = integer1-integer2 , there is no inbuilt function like difference and hence getting the error.

**********************************

Question 6 :

temp.py

#Python program that converts a Fahrenheit temperature into its Celsius temperature equivalent.
def main(): #function
# asking user to enter Fahrenheit temperature
Fahrenheit = float(input("Enter Fahrenheit temperature : "))   
# converting temprature in celisus
Celsius = 5.0/9.0*(Fahrenheit - 32.0)
# print Fahrenheit Temperature
print("Fahrenheit Temperature = ",str(Fahrenheit))
# print Celsius Temperature
print("Celsius Temperature = ",str(round(Celsius,1)))   

main() #function call

Screen for Indentation :

*******************************

Output :

Screen 1 :Screen showing F to C conversion

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

In this assignment, you will develop a simple Web server in Python that is capable of...
In this assignment, you will develop a simple Web server in Python that is capable of processing only one request. Specifically, your Web server will (i) create a connection socket when contacted by a client (browser); (ii) receive the HTTP request from this connection; (iii) parse the request to determine the specific file being requested; (iv) get the requested file from the server’s file system; (v) create an HTTP response message consisting of the requested file preceded by header lines;...
Please use python and run in IDLE Question 1 Write functions that do the following: i)...
Please use python and run in IDLE Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii)...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
develop/ list the financial objectives of a start up bar & grill. also list/develop strategic objectives...
develop/ list the financial objectives of a start up bar & grill. also list/develop strategic objectives of a start up bar and grill
Python: High school assignment, please keep simple In python: Use the following initializer list to create...
Python: High school assignment, please keep simple In python: Use the following initializer list to create an array: twainQuotes = ["I have never let my schooling interfere with my education.", "Get your facts first, and then you can distort them as much as you please.", "If you tell the truth, you don't have to remember anything.", "The secret of getting ahead is getting started.", "Age is an issue of mind over matter. If you don't mind, it doesn't matter. "]...
Objectives To develop a recursive solution that reurns a tuple To develop a program that manages...
Objectives To develop a recursive solution that reurns a tuple To develop a program that manages bad input Description Write a program (sumAndCount.scala) that uses a recursive function that reads Int values from a user one at a time until the user types in the word "quit" (case insensitive!). Your function should return a tuple containing 2 Int values. The first should be the sum of all the Ints, and the second should be the number of Ints entered. Your...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the code below in the new file (you may omit the comments, I included them for explanation #Python Code Begin x = int(input("Enter a number: ")) y = int(input("Enter another number: ")) print ("Values before", "x:", x, "y:", y) #add code to swap variables here #you may not use Python libraries or built in swap functions #you must use only the operators you have learned...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
Python: IDLE exercise 1. Start by running, in the shell, the following assignment statement: s1 =...
Python: IDLE exercise 1. Start by running, in the shell, the following assignment statement: s1 = 'abcdefghijklmnopqrstuvwxyz' Now write expressions—on separate lines of code—using sting s1 and the indexing operator that evaluate to 'm', 'p', 'z', 'e', 'a'. 2. Write Python statements that correspond to the following: a. assign to variable flowers a list containing strings 'rose', 'bougainvillea', 'yucca', 'marigold', 'daylily', and 'lily of the valley'. b. Write Boolean expressions that evaluate to True if the string ‘carrot’ is in...
Use Python: # Problem Set 01: - Develop neurons and print truth table of the following...
Use Python: # Problem Set 01: - Develop neurons and print truth table of the following 2-input logic gates: AND, OR, NAND, NOR, XOR, XNOR and 1-input NOT gate (Notice: use Markdown to explain how you developed a neuron, and to insert images showing the truth table of logic gates before coding) # Problem Set 02: - Develop neuron and print truth table of XOR gate using only NAND gates - Develop neuron and print truth table of XOR gate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT