Question

#Python Help please Modify the mistakes in my code , so that it prints the same...

#Python

Help please

Modify the mistakes in my code , so that it prints the same statement four times. Using four distinct techniques—hard-coding, commas, concatenation, and string formatting. The hard-coding is already done. The other three techniques have been started but they contain mistakes. These techniques should each use all three of the provided variables. Once the mistakes have been corrected, run the script and upload a picture of the program running to make sure that it prints the statement identically four times:

Found 12 lights in the 5 mi. buffer and 20 intersections.

Found 12 lights in the 5 mi. buffer and 20 intersections.

Found 12 lights in the 5 mi. buffer and 20 intersections.

Found 12 lights in the 5 mi. buffer and 20 intersections.

Correct the mistakes in this script so that it prints the same statement 4 times, using 4 different methods:

1) hard-coding

2) commas

3) concatenation

4) string formatting

Code:


trafficLightsCount = 12
bufferDist = '5 mi.'
intersectionCount = 20

# 1) Entirely hard-coded statement. Don't change this one.
# Make the other print statements match this output.
print 'Found 12 lights in the 5 mi. buffer and 20 intersections.'

# 2) Modify the code to correctly use the three variables
# and use commas to join expression components.
print 'Found', trafficLightCount, lights in the intersectionCount buffer and, ' buffereDist' 'intersections.'

# 3) Modify the code to correctly use the three variables
# and use concatenation to join expression components.
print 'Found' + trafficLightCount + lights in the buffereDist buffer and intersectionCount intersections.'

# 4) Modify the code to correctly use ALL three variables
# and use the string 'format' method.
print 'Found {1} lights in the {0} buffer and 30 intersections.'format(trafficLightsCount, bufferDist)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

trafficLightsCount = 12

bufferDist = '5 mi.'

intersectionCount = 20

# 1) Entirely hard-coded statement. Don't change this one.

# Make the other print statements match this output.

print 'Found 12 lights in the 5 mi. buffer and 20 intersections.'

# 2) Modify the code to correctly use the three variables

# and use commas to join expression components.

print 'Found', trafficLightsCount, 'lights in the', bufferDist,'buffer and', intersectionCount, 'intersections.'

# 3) Modify the code to correctly use the three variables

# and use concatenation to join expression components.

print 'Found ' + str(trafficLightsCount) +" lights in the "+bufferDist +' buffer and '+str(intersectionCount)+' intersections.'

# 4) Modify the code to correctly use ALL three variables

# and use the string 'format' method.

print 'Found {0} lights in the {1} buffer and {2} intersections.'.format(trafficLightsCount, bufferDist, intersectionCount)

Add a comment
Know the answer?
Add Answer to:
#Python Help please Modify the mistakes in my code , so that it prints the same...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out...

    JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa. In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa. import java.util.*; // for the Scanner class...

  • PLEASE DO THIS IN PYTHON!! 1.) Goal: Become familiar with The Python Interpreter and IDLE. Use...

    PLEASE DO THIS IN PYTHON!! 1.) Goal: Become familiar with The Python Interpreter and IDLE. Use IDLE to type, compile, and run (execute) the following programs. Name and save each program using the class name. Save all programs in one folder, call it Lab1-Practices. Save all programs for future reference as they illustrate some programming features and syntax that you may use in other labs and assignments. ================================== Program CountDown.py =================================== # Program CountDown.py # Demonstrate how to print to...

  • PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of...

    PLEASE HELP! python code Problem 4. Define the function pythagorian_coprimes (n=100) that prints all pairs of positive integer numbers (a, b) such that c = a + b is also a whole number and 1 <c<n. Include only those triples that are co-prime (do not have any common divisors other than 1). For example, (3, 4, 5) is okay but (30, 40, 50) should be skipped. Help: As a starting example, examine the function pythagorian_triples that yields all triples. Modify...

  • Python   #complete the following lines of code wherever indicated. 5 question 20 points a piece #you...

    Python   #complete the following lines of code wherever indicated. 5 question 20 points a piece #you may use your book and internet but no form of messaging or communication #QUESTION 1 #Read in the file exam_file.txt #Print to the console every other line #QUESTION 2 #Read in exam_file.txt #split file into words #write to a file called question2.out that contains 1 word per line (words can occur more than once) #QUESTION 3 # Print out all the Middle Initials in...

  • Python #complete the following lines of code wherever indicated. 5 question 20 points a piece #you...

    Python #complete the following lines of code wherever indicated. 5 question 20 points a piece #you may use your book and internet but no form of messaging or communication #QUESTION 1 #Read in the file exam_file.txt #Print to the console every other line #QUESTION 2 #Read in exam_file.txt #split file into words #write to a file called question2.out that contains 1 word per line (words can occur more than once) #QUESTION 3 # Print out all the Middle Initials in...

  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Please help me edit my code so it looks a little different but produces the same...

    Please help me edit my code so it looks a little different but produces the same output. Me and classmate did the assignment correctly but are afraid of plagarism. Here is my code. /** * @(#) * @author * @version 1.00 6/25/2017 3:00 PM * Program Purpose: Code a program that computes sales revenue * to-date to determine the status of the company’s * sales revenue and whether a year end bonus is in store for the employees. */ import...

  • #1. Operators and values, expressions Please correct the following code to make it print the given...

    #1. Operators and values, expressions Please correct the following code to make it print the given expressions and their answers well (3pts). public class DataTypes {    public static void main(String[] args) {       System.out.println("5*8/6 = " + 5*8/6);       System.out.println("(2*6)+(4*4)+10 = " + (2*6)+(4*4)+10);       System.out.println("6 / 2 + 7 / 3 = " + 6 / 2 + 7 / 3);       System.out.println("6 * 7 % 4 = " + 6 * 7 % 4 );       System.out.println("22 + 4 * 2 = "...

  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT