Question

Exercise 1.1 from your textbook recommends that you try to make mistakes when experimenting with a...

Exercise 1.1 from your textbook recommends that you try to make mistakes when experimenting with a new programming feature. This kind of experiment helps you remember what you read; it also helps when you are programming, because you get to know what the error messages mean. It is better to make mistakes now and on purpose than later and accidentally. (Downey, 2015, 7) For this Learning Journal, first answer the following questions based on Exercise 1.1. If you are trying to print a string, what happens if you leave out one of the quotation marks, or both? You can use a minus sign to make a negative number like -2. What happens for each of the following? >>> 2++2 >>> 2--2 >>> 2+-2 >>> 2-+2 In math notation, leading zeros are OK, as in 02. What happens if you try this in Python? What happens if you have two values with no operator between them? Next describe at least three additional Python experiments that you tried while learning Chapter 1. Show the Python inputs and their outputs, and explain what you learned from the results.

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

The answers are described in Python 3 as programming language:

1. a) Printing a string "Hello World" with quotation marks:

  • Input Code:

print("Hello World")

  • Output:

b) Printing a string "Hello World" without quotation marks:

If we put Hello World without one of the quotation marks or even both, the compiler will throw a syntax error as shown in the output. This is because if we put a word inside print function, the compiler processes it as a variable (example string in our case) and expects it to be declared.

  • Input Code:

print(Hello World)

  • Output:

  • Input Code:

print("Hello World)

  • Output:   

2. Evaluating mathematical expressions with two operators in between number:

  • Input Code:

print(2++2)

print(2--2)

print(2+-2)

print(2-+2)

  • Output:

​​​​​​​

This is because the compiler resolves its as:

  • 2+(+2)=2+2=4
  • 2-(-2)=2+2=4
  • 2+(-2)=2-2=0
  • 2-(+2)=2-2=0

3. Evaluating leading zeros in a number:

Python compiler treats a number with leading zero as invalid token.

  • Input Code:

print(401+004)

print(02)

  • Output:

​​​​​​​

4. If we have two values with no operator between them, the Python compiler treats it as a single value. An example is illustrated with Python code and output.

  • Input Code:

print(401+4)

print(4014)

  • Output:

​​​​​​​

Add a comment
Know the answer?
Add Answer to:
Exercise 1.1 from your textbook recommends that you try to make mistakes when experimenting with a...
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
  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • Read the article below and in your own words, (1-2 sentences) what is the "true direction"...

    Read the article below and in your own words, (1-2 sentences) what is the "true direction" or right way to interpret nature, according to Bacon? True Directions Concerning the Interpretation of Nature (1620) Francis Bacon Those who have taken it on themselves to lay down the law of nature as something that has already been discovered and understood, whether they have spoken in simple confidence or in a spirit of professional posturing, have done great harm to philosophy and the...

  • What are your top 3 takaways from this article? It’s always tempting to see the present...

    What are your top 3 takaways from this article? It’s always tempting to see the present moment as the peak of chaos and disruption, whether we’re talking about politics or just how those teenagers behave today. The same is true in marketing, because in many ways that profession is always in a state of chaos and disruption. But I don’t think it’s hyperbole to apply “peak chaos and disruption” to social media marketing in the first quarter of 2018. Let’s...

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