CS 1101 - AY2020-T5 - Discussion Forum Unit-1
CS 1101 - AY2020-T5 - Discussion Forum Unit-1
Programming languages like Python are formal languages with strict syntax rules. But those rules
can change over time with newer versions of the programming language. Your textbook covers
Python 3, but you may only have access to Python 2.
Download and install a working Python environment, preferably Python 3, or get an account with the
Virtual Computer Lab or PythonAnywhere. Refer to the Software Requirements/Installation section
of the course syllabus for details.
Type the statements below into your Python interpreter. For each statement, copy the output into
your Discussion Assignment and explain the output. Compare it with any similar examples in the
textbook, and describe what it means about your version of Python.
When you reply to your peers’ submissions, compare their results with yours.
Cheers,
148 words
Permalink
The statement above means that the print value requires the inclusion of parentheses to make
it a function in the statement.
>>> 1/2
0.5
The output 0.5 indicates that its a floating-point number.
>>> type(1/2) Class in the output indicate the category of the value which is float as in floating-
point number.
>>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
The statement above means that having a leading zero in integer statement in python is not
allowed.
>>> 1/(2/3)
1.5
The output 1.5 indicates that its a floating-point number.
From the example print('Hello, World!') in chapter 1 under section 1.3 the first program in Think
Python by (Downey 2015), and getting the same output in the interpreter as the example given
it means that I use the version of Python 3.
161 words
/
Permalink Show parent
Awesome! You were able to show that you're using Python 3 instead of Python 2.
Weren't you supposed to explain the output though, instead of just saying what it was?
30 words
Good work
Explicit, but try explaining in more detailed manner
Good reference
Try better next time
16 words
Hi
you have answered all the questions correcly which is great, but i think you needed to add
more explanation into the answeres
23 words
You did great about your summary and talk about the output of every statement but you
forgot to explain the output instead of saying what it was?
But you did great good job.
33 words
11 words
it is very clear
4 words
Good job,
It would be better if the explaination was more seperated.
Lets go Python!
15 words
Simple Tests
by Virgil Vega - Friday, 19 June 2020, 3:21 AM
The assignment was to run some simple lines of code and explain the output.
"File "<stdin>", line 1" Points to something in the first line of code.
The "print 'Hello, World!'" and the "^" underneath the first quotation mark point to a specific
character.
Finally, the "SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello,
World!')?" Shows that there was an error in that specific line of code at that specific character. It /
gives a "SyntaxError", tells you what it was expecting or what it's probably missing (A
parentheses), and gives a suggestion as to what you might have meant.
All of this happened because this line of code was run on Python 3, instead of Python 2. In
Python 3 "print" is a function, and requires the correct syntax of a function (Parentheses after
it's name). "In Python 2, the print statement is slightly different; it is not a function, so it doesn’t
use parentheses." (Downey, A. (2016). Think Python.) If this line of code was run on Python 2,
the result would be: "Hello, World!"
>>> 1/2
0.5
Python took the first integer, the operator, and the second integer, and translated it into "0.5".
>>> type(1/2)
<class 'float'>
"type()" Is a function that asks Python what type of value is inside of the parentheses. In this
case "1/2" was inside of the parentheses. "1/2" isn't a single value, it's two values that need to
be simplified, so python does that, and simplifies it into "0.5", a "floating-point number"
(Downey, A. (2016). Think Python.). "0.5", the result of "1/2", is a floating-point number, and so
Python returns "<class 'float'>." "class" is "the type of value", and "float" is a shortened form of
"floating-point number."
>>> print(01)
File "<stdin>", line 1
print(01)
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o
prefix for octal integers
As stated before, Python points to a specific character in a specific line of code ("1"), gives an
error ("SyntaxError"), and tells you what the error is ("leading zeros in decimal integer literals
are not permitted"). This time it doesn't give you a suggestion though, instead it tells you to type
"0o" at the beginning, the correct syntax for starting an integer with 0.
Python follows the order of operations, meaning that it divided 2 and 3 first, then divided 1 by
the result.
I performed some simple tests, and explained the outputs. Because of certain outputs, I am
able to state that I am using Python 3, and not Python 2.
497 words
Excellent! Your explanations are very insightful and relevant to the questions. I grade you
10 (A).
16 words
hi
i really like your work it is very well put together with great explanations
15 words
Excellent
Your explanations is great you explain every statement in a good way also helped me to
understand everything
I graded you 10
Very good Virgil
26 words
A detailed and informative assignment. Explained how Phyton parse the statement step by
step.
14 words
I very much like the explanations here and the detailed manner of it all. Also very readable!
The differentiation of Python 2 and 3, is very well welcomed. 10/10. I do like the ease that
you were able to explain the floating number, type, and value. Excellent!
48 words
Your answer was very clear and very well explained. I loved the way you formatted your
text, which makes the reading pretty easy for us. Nice job!
27 words
Very detailed explaination . The presentation is also so easy to understand and very
detailed!
It makes learning python interesting.
Good Job!
21 words
Hello Virgil
You have done very good work, easy and understood explanation. Each statement you
have run are totally correct and clear enough. Again you have done an excellent work.
Good luck
/
Greetings
33 words
Python 3.8.3
Not finished
Nice explanation, but not detailed enough
37 words is not so good for explaning the assignment
Try better next time
22 words
hi
you need to add more explanations to your answers in the print 'hello world' why did you
get the error? what can you do to solve it. go have a read of what people have posted and
how they have answered the questions and come back next week with a great reply
53 words
Permalink Show parent /
Re: Discussion Forum Unit-1
by Mathew Ojo - Saturday, 20 June 2020, 10:28 PM
Incomplete, you need to explain in detail and attempt all questions as stated.
13 words
Austin
You didn't finish the assignment and you did not do what was required.
You can try again it's very easy.
21 words
Hey Austin,
You should have explained a little more about every command line you executed and the
syntax errors that you came up with some of them. It was also expected to see a
comparison of the Python version you used with others.
43 words
Hi Austin,
You have all the exact syntax as you were asked to do. However, detailed explaination
would be very helpful for people to understand. Lets make learning python easy by giving
details to begineer like me.
Good Job
39 words
Hello Austin
You have not done your task yet, you need also to provide clear explanation or feedback of
your work.
Greetings
22 words
by Tofunmi Adegoke - Saturday, 20 June 2020, 6:01 AM
^
SyntaxError: invalid syntax
>>>
>>> 1/2
Output: 0.5
0.5 which is the result is displayed because, the right operator (/),which denotes division is used
rightly.
>>>type (1/2)
Output:<class 'float'>
>>>
1/2 is a value of the type "floating point number"
Which is denoted with <class 'float'>,values that are fractions or decimal numbers are generally
of the type" floating point number"
>>>Print(01)
Output:File "<stdin>", line 1
print(01)
^
SyntaxError: invalid token
>>>
In normal mathematics, 01 essentially mean 1, but in programming,it is completely different.
(Reference : Think python)
In the interpreter,1 is a token,01 is not,it is not part of the syntax or structure of the
programming language interpreter by my program interpreter
>>> 1/(2/3)
1.5
Since the operator ,/ which is division sign in maths is used correctly,the interpreter displays it
correctly.1/(2/3) is the inversely of 2/3 equals 3/2 which is 1.5.
What I learnt
Correct applications of operators leads to programs without bugs
202 words
Nice work in explaining the outputs with great detail, keep up the good work.
14 words
Thanks
1 words
14 words
great work with explaining it is clear. though i wasn't able to provide explanation of of the
last one because i didn't understand.
23 words
You have done your task very good and provided them with clear explanation. Wish you
good luck and more progress.
Greetings
23 words
>>> 1/2
Output: 0.5
0.5 which is the result is displayed because, the right operator (/),which denotes division is used
rightly.
>>>type (1/2)
Output:<class 'float'>
>>>
1/2 is a value of the type "floating point number"
Which is denoted with <class 'float'>,values that are fractions or decimal numbers are generally
of the type" floating point number"
>>>Print(01)
Output:File "<stdin>", line 1
print(01)
^
SyntaxError: invalid token
>>>
In normal mathematics, 01 essentially mean 1, but in programming,it is completely different.
(Reference : Think python) /
In the interpreter,1 is a token,01 is not,it is not part of the syntax or structure of the
programming language interpreter by my program interpreter
>>> 1/(2/3)
1.5
Since the operator ,/ which is division sign in maths is used correctly,the interpreter displays it
correctly.1/(2/3) is the inversely of 2/3 equals 3/2 which is 1.5.
What I learnt
Correct applications of operators leads to programs without bugs
202 words
Good, but your explanation is not well detailed. The last question states that we should
explain what the results mean to our version of Python which could either be Python 2 or
Python 3 based on the output you get from the interpreter. B (8)
45 words
Ok thanks
Wanted to add it but time wasn't enough to edit
Thanks!
13 words
I do think you did a good job, but I agree with Mathew that it would need a bit
more explanation. Other than that, good job and I look forward to your next
forum discussion post. :)
36 words
Re: Discussion Forum Unit-1 /
by Tofunmi Adegoke - Monday, 22 June 2020, 11:44 PM
Thank you
2 words
From what I understand, the latest version of Python doesn’t not need parenthesis.
13 words
Statment 1
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
This print statement print 'Hello, World!' produced a syntax error because the python version
used is 3.8 and the correct syntax would need parentheses and would be formatted like this
print ('Hello, World!'). If we run this statement in the python 3.8 interpreter, we will get this
result.
Hello, World!
Statement 2
>>> 1/2
0.5 /
This statement uses an operator, an operator is normally a mathematical function, the operator
used in this example is the division operator / and if you divide 1 by 2 is the result is equal to
0.5.
>>> 40 + 2
42
>>> 43 – 1
42
>>> 6 * 7
42
Statement 3
>>> type(1/2)
<class 'float'>
This statement returns the type of value, the value of the expression 1 / 2 is a float because the
result of the mathematical operation is 0.5. A float is defined as a number that has a fractional
part.
we can also find other class values using, the type () function and can be seen below:
type(1)
<class 'int'>
type('string')
<class 'str'>
Statement 4
>>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
This print statement produced an error because in python an integer cannot start with a
leading zero, nor can it be a variable because variables cannot start with a numeric character. If
we need to print 01 we could output the value as a string and use print ('01').
print('01')
01
Statement 5
>>> 1/(2/3)
1.5
This statement performs a computation on the expression 1/(2/3). The interpreter will follow
the standard order of operations BODMAS and will perform the division first (2 / 3) because the
parentheses has to be calculated first, the next step in in the calculation is to divide 1 /
0.6666666666666666 which is equal to 1.5.
Reference:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This
book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC
3.0).
450 words
Excellent. 10/10
3 words
Very detailed explanation with extra examples shown as well. Great effort and work!
13 words
Awesome! You could also just ask it to print(0o1), but I'll bet you already knew that. I love
how you tried the 'Hello, World' statement in Python 2 and Python 3!
32 words
This is a very clear and concise! I personally love that there's a lot of explanation. It's very
user friendly if someone was looking at this with fresh eyes.
29 words
that was so insightful, and very detailed explanation, keep up with the good work
14 words
i like how you explained everything in details. i didn't provide explanation of the last one
cause i didn't understand though i had feeling it was like this.
I also tried both single and double quotes to parse text and they both worked.
15 words
Hi Adrian
Hi Adrian,
Foremost thanks for the detailed explaination . It is very helpful for begineer like me to
understand aout some basic python. I also liked the presentation .The reference that you
have included makes it more perfect.. Way to go. Good luck for the course .
45 words
>>> 1/2
0.5
The operator " / " performs division
It's a similar command like >>>6*7
>>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
We received Syntax Error because if we use integer numbers, must write it without 0 in start
>>>print(1) give us 1
>>> 1/(2/3)
1.5
Similar mathematical calculation. Before calculating in parentheses.
Another example from the book of compound calculation>>> 6**2 + 6 witches give us 42
138 words
Well explained with solution given for statement with syntax error. Would be even better
to include explanation on differences between Python 2 and 3 for the first statement as
Python 2 is able to take the print statement without parentheses.
40 words
blob:https://www.icloud.com/79f2497f-2436-42f2-bfea-03178a9ff58d
6 words
1/2:
result: 0.5
type(1/2):
meaning after it parsed 1/2, Python determined it is a floating number or a decimal number.
print (01):
It has thrown a syntax error. Python does not allow for leading zeros for numerical data.
1/2/3:
/
0.16666666666666666
It has taken 2, divided it by 1, and then divided 3 by the result. I’m assuming that is the
remainder. As you can see, fractional data entered literally would cause less than accurate
results as Python uses decimals only. It would be best to convert fractional data into decimal
before using it for calculations.
169 words
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello world!')?
------------------------------------------------------------------------------------------------------------------------------------------
--------
2) This input represents an arithmetic operation, where the "/ "operator performs a division. 1
divided by 2, equals 0.5.
>>> 1/2
/
0.5
------------------------------------------------------------------------------------------------------------------------------------------
--------
3) On Python 3 numbers that start with 0 are not accepted as valid numbers. We solve this
issue by wrapping 01 with brackets.
>>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o
prefix for octal integers
------------------------------------------------------------------------------------------------------------------------------------------
--------
4) The input represents an arithmetic expression, in which the result is 1.5.
>>> 1/(2/3)
1.5
164 words
I love the color coding! You didn't quite "describe what it means about your version of
Python" though.
18 words
The color coding is excellent. I do appreciate that, and it's readability. I did have the same
issue that I did not exactly provide what the version of Python meant, but this good.
33 words
>>> 1/2
The output
0.5
This means that Python interpreter van used as a calculator too because we type 1/2 the result
is 0.5, also if we write 2+2 the results will be 4.
This means that the zero cannot be used with decimal integer literals
1/(2/3)
The output
1.5
/
This is a calculation because python interpreter can be used as a calculator.
217 words
Great job in explaining the output results, I have similar answer as I am also using python
3. Keep up the good work.
23 words
1)
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(‘Hello, World!’)?
Hello, World
Explanation :
print ‘Hello, World!’ is a correct input statement for Python 2 but not for Python 3. Hence,
Python 3 displays an syntax error message when I type in the command as the missing
parentheses. So I updated the print statement with opening and closing parentheses : >>>
print('Hello, World!') to allow Python to compute the statement. Print statement display the
values in its parentheses Hello, World! In the output line
2)
>>> 1/2
0.5
Explanation :
Input 1/2 into Python then it will compute the input as 1 divided by 2 as / is a division operator
/
symbol in Python Hence the output value is 0 5 which is a float type value by default
symbol in Python. Hence, the output value is 0.5 which is a float type value by default.
3)
>>> type(1/2)
<class 'float'>
Explanation :
Type statement allow python to indicate the type of value in it, whether it is integer, string or
floating-point number type. 1/2 is categorized as floating-point number in Python.
4)
>>>print(01)
print(01)
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
Explanation:
Python is not able to take leading zeros in decimal integer. To display leading zero integer with
2 digits such as 01 at output, we can use the following code :
>>> print(f"{1:02d}")
01
5)
>>> 1/(2/3)
1.5
Explanation :
/ is the divide operator. By default, value in the bracket which is 2/3 will be computed first. So 2
is divided by 3. Then Python divide 1 over 2/3 to obtain the final output of 1.5.
292 words
Hello Chai,
Your response provided a very insightful and clear explanation of the topic. You answered
all the questions correctly. You just forgot to tell us the exact version of Python and the IDE
you are using. Great job overall!
40 words
Thanks Cesar for your input. Will take note of the instruction in details next time. :)
15 words
Nice explanation.
2 words
Hi Chai,
I like how you detailed and highlight your post, good job.
13 words
Explanation: It shows error due to missing parentheses. Because print displays the result on the
screen. The parentheses indicate that print is a function. Without parenthesis the output shows
an error.
Here is statement with parenthesis. The outcome shows hello, world with out error.
Statement >>> print ('hello, world'!)
Output hello, world!
Explanation: When hello world is placed in parenthesis (‘hello, world!’) the output changed to
hello, world!
Nice work
You really did well
However,you probably unknowingly omitted to type the output of the statement
.... because type is defined as class floating point number should finish the sentence
However, I'll really love you explanations
49 words
>>> 1/2
0.5
This is preforming division via the Python operators, which has halved 1 into 0.5
>>> type(1/2) Because it is not an integer, any number with a decimal is to be a floating point
number. We are back at 0.5 once again. As another example, if >>>type (2) is used, there is the
different classification for integers. This is also able to be shown by
>>> type (2)
Again, the same difference is seen once more while typing in >>> type (2.0)
>>> print(01)
File "", line 1
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
Leading 0s are not permitted, for this function to work and keep it as an integer - it can be
written as such:
>>> print(1)
1
Or for octal integers
>>> print(0o1)
>>> 1/(2/3)
1.5
This equation is dividing (2/3) first, and then dividing it by 1. If using without the parenthesis as
making it a string, it will end up being >>> 1/2/3
0.16666666666666666 therefor not correctly divided.
/
236 words
236 words
Good explanation
Keep up!
You really did well
Nice
You should have tried talking about you using python 3 and not 2
However,You explained superbly well
25 words
output: <class 'int'>
------------------------------------------------------------------------------------------------------------------------------------
>>> print(01)
Input: >>> print(01)
Output: 1
The statement above is considered as a print statement. The program in both Python 3 and
Python 2 runs the same output.
------------------------------------------------------------------------------------------------------------------------------------------
1/(2/3)
Input: 1/(2/3)
The above statement runs in both Python 2, 3 into an error, because we do not start a print
statement with numbers. Thus, to debugging the statement it has to be (2/3) without 1/
==============================================================================
212 words
/
Permalink Show parent
Nice Sahar! I really like your comparisons, it helps to see more output examples.
for >>> type(1/2) in python 3 'float' is returned because the answer to 1 divided by 2 is 0.5,
which is a floating-point.
Your comparison >>> type(2) is correct and returns
>>> print(01)
gives this
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
You must remove the leading zero or use the "0o" prefix to avoid the error.
>>> 1/(2/3)
1.5
two thirds(2/3) goes in to one, 1.5 times
142 words
Greetings
Sahar
/
63 words
No problem Sahar!
>>> 1/2
0.5
By calling type(), we are asking what kind of value this is between the parentheses, an integer,
floating-point number or a string.
A floating-point number is defined as: “A type that represents numbers with fractional parts”
(Downey, 2015, p.7).
Because the quotient of 1 divided by 2 is 0.5, that is a floating-point number and that is why
class ‘float’ was returned.
>>> print(01)
File "", line 1
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
If you want to return the integer 1 you can’t place a 0 in front of the number, that would be a
syntax error. You can put print(0o1) to avoid that syntax error, or simply remove the zero in
front of the one as print(1).
>>> 1/(2/3)
1.5
Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, MA: Green
Tea Press.
285 words
John
Great Job. Your explanation and the result is correct.
10 words
So, I was curious then I use both of the version python 2 and python 3 for the assignment.
/
>>> print 'Hello, World!'
File "<stdin>", line 1
print 'Hello, World!'
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
Thus, the print statement does not have parentheses and because I am using Python 3.
However, in chapter 1 of our reading material I saw a relation and explanation to the print
statement (Downey, 2015).
The print statement here worked in Python 2 because it's not a function, so it doesn't use
parentheses.
>>> 1/2
0.5
The output shows that the Arithmetic operator performs a division and is similar to >>> 84 / 2
42.0 under chapter 1.4, Arithmetic operators (Downey, 2015).
>>> type(1/2)
<class 'float'>
The output shows that the value 1/2 is a floating-point number and it is similar to >>> type(42.0)
<class'float'> under chapter 1.5, Values and types (Downey, 2015).
>>> print(01)
File "<stdin>", line 1
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
The output shows that leading zeros in decimal integer literals are not permitted. It is quite
similar to >>> 1,000,000 under Chapter 1.5 Zeros cannot start a decimal integer
The output shows that the Arithmetic operator performs a mathematical calculation and is
similar to >>> 84 / 2 42.0 under chapter 1.4, Arithmetic operators (Downey, 2015).
Reference
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This
book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC
3.0).
272 words
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
We get following error in output because we are missing parentheses (), at the beginning and
end of value ‘Hello, World’
the correct format for the print function is print('Hello, World!').
>>> ½
0.5
½ represents the arithmetic operation of division, 1 divide be 2 which results in an answer of
0.5.
>>> print(01)
This command will result in SyntaxError: invalid token on screen, because in python 3, literal
integer starts with 0, also interpreted as octal need prefix of 0o.
So instead of writing print(o1), should write print(0o01) and it will output as 1, without any
error.
>>> 1/(2/3)
The answer for this math equation will be 1.5.
as a result of the equation of 1*3/2.
159 words
Print statement
>>> print 'Hello, World!'
Hello, World!
>>> print('My name is Leul')
My name is Leul
This will give as the output of the text written inside the single quotation, the quotation
is the beginning and end of the text.
__________________________________________________________________________________________
Arithmetic operators
>>> 1/2
0.5
>>> 4/2
2.0
>>>
By using the arthmetic operator division (/) and output the result
_________________________________________________________________________________
Type of a value
>>> type('2') checking the type of the value inside the bracket and it is string becuase it
is inside single qutation
<class 'str'>
>>> type(2) when we see this one it is a value of int (integer) so numbers dont use
qutation
<class 'int'>
__________________________________________________________
>>> print(01) the output is differnet in python version Python 3, leading zeros are not
allowed on numbers.
SyntaxError: invalid token ---- version 3 and above
>>> print(01) when we come to version Python 2 leading number has a meaning for
python which is an octal number and the result will be decimal
1 ---- version 3 and above
>>> print(0101)
65
__________________________________________________________________________________
>>> 1/(2/3)
1.5 This artimatic opersation will result a float number type of 1.5
___________________________________________________________________________________
i have 2 differnet version on my machine v2.7 and v3.7 i found all the output the same on /
a e d e et e s o o y ac e . a d 3. ou d a t e output t e sa e o
bothe version except the print(01) which i mentioned in the above
212 words
for the print function, I was tiring to explain what the output looks like in v2 and v3
sorry I didn't mention that the string inside the single quotation need a bracket in
v3
>>> print 'Hello, World!'
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?
50 words
Hi Leul,
Good job, on the explanation, your post shows your understanding of the assignment and
also how comfortable you are exploring the app.
24 words
Input 1:
Output:
>>> 1/2
Output:
0.5
Description: This code used the arithmetic operator “/” to perform division.
Input 3:
>>> type(1/2)
Output:
Description: This code uses the interpreter to determine what type of value is inputted. In this
case 1/2 would result in 0.5 which is a floating-point number or ‘float’.
Input 4:
>>> print(01)
Output:
Description: A syntax error occurred due to a leading zero which violates the syntax rules of this
programming language. To fix, either remove the zero or place a period after the zero
depending on your desired outcome.
Input 5:
>>> 1/(2/3)
/
Output:
1.5
Description: This code uses the arithmetic operator to divide the integer “1” by the solution
within the parenthesis.
Conclusion: All of my inputs provided similar results to the textbook since we were both using
version 3 of python.
189 words
My output for input 3 was <class 'float'>. Sorry, I must have deleted it on accident.
16 words
well done really easy to read and understand what you were trying to say
14 words
Output: Syntax Error. Parentheses are missing therefore print is not regarded as a function.
/
Similar: print ('Hello World!')
Similar: print ( Hello, World! )
>>>1/2
Similar: 42.0
>>>type(1\2)
Output: <class 'float' > . type is used to indicate the type a value contains or has.
Similar: 42.0
>>>print(01)
Output: the zero(0) for octal does not work on the upgrade (Python3)
>>>1/(2/3)
These results clearly states that python 3 yields accurate results and is free of the bugs that
affected outputs in python 2.
99 words
input: 1/2
output: 05.
explanation: python recognizes this as a simple fraction. 1 divided by 2.
input: type(1/2)
output: explanation: Float() is a function that converts a string to a float value and returns the /
result. If it fails for any invalid input, then an appropriate exception occurs.
input: 1/(2/3)
output: 1.5
explanation: python 3 computes this as 1.5
142 words
Great work, your explanations were good and clear, keep going.
10 words
Dear Kenneth!
Thank you for the work you made. The only thing I want to mention - Float() in the third
case is not a function. It's a class and 0.5 is a class instance.
34 words
/
Input Output
^
>>>
The code is missing ( ) that are used in most programming language. Languages requires a
good grasp of grammar. Thus, gives out an “Syntax Error” which means that this language
needs to be written in a certain manner.
Input Output
the arithmetic problem is easily been solved but the following output is in decimal. If we want,
we can show the output as fraction also
>>>1/2
Input output
Type tells what kind of class numbers/letter are like for e.g. o.5 or any number containing
decimals are called floating-point number because there is no fixed number.
/
input output
print(01)
^
>>>
This one was pretty confusing for me to understand but after some research I have concluded
that python 3 uses octal numeral system which has a based 8 ^ to convert numbers to its
decimal form. (0, 1, 2, 3, 4, 5, 6, 7) is the range thus base-8. Leading zeros are not allowed in
python 3
But I still don’t get how to solve this. Do we convert it to binary numbers?
input output
Reference:Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea
Press. This book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported
(CC BY-NC 3.0).
280 words
I like the way you explain each problem, on the leading number problem in my
understanding python V2 take it as octal number and it will give us decimal conversion
output, but when you come to python 3 leading zero is not acceptable; so you are right
47 words
Permalink Show parent /
Re: Discussion Forum Unit-1
by Faiza Sheikh - Wednesday, 24 June 2020, 7:58 PM
really?
To use octal numbers in Py3 you should use syntax 0o1234 (o is important)
14 words
Hi Faiza,
I agree with the first response to your post. You did a good job on the explanations.
19 words
Very detailed post that really showcased your already apparent knowledge of coding. We
both got the same exact results. Good job on the assignment.
24 words
The output for the statement type(1/2) when I pasted it to python was
<class 'float'>
/
26 words
Dear Iman!
For 3 - I think that you have a problem with a symbol. It can be not a division symbol but
something looks alike. For me it is better not to copy but write the code manually - it
preserves you from this kind of errors at least
63 words
you done well but i think you needed to explain a bit more
13 words
For python3 print is a function which requires a parameter and not an interpreter statement
>>> 1/2
0.5
type() function returns object type (kind of an object which contains methods that can be used
with this kind of object)
>>> print(01)
File "", line 1
print(01)
^
SyntaxError: invalid token
0DDD was the syntax for octal digits in python2. For py3 octal syntax is 0oDDD so 0DDD is
marked as an error to avoid collisions
>>> 1/(2/3)
1.5
137 words
The result of this statement is that there is a missing (). If I wrote print (‘Hello, World1’)
The output would be correct.
>>> print ('Hello, World!')
Hello, World!
>>> While in version 2 of Python parentheses aren’t needed because the print statement is not
a function, in this version they are, print is a function.
2) >>> 1/2
0.5
/
>>> This is a arithmetic for division. The operator that is used for division is /. Other operators
are +, -, * and ** which does exponentiation.
3) >>> type(1/2) >>> Every value a program uses is of some type. Some might be string like Hello
World! And others are numbers. Type is a function you use when you don’t know what type of
value you’re using. The most interesting example in this chapter is number 1,000,000 written
with commas.
>>> 1,000,000
(1, 0, 0)
>>> 1000000
1000000
>>> The first one is a sequence of integers separated by a comma. The second one is a simple
integer.
4) >>> print(01)
SyntaxError: invalid token
>>> In Python 3, leading zeros are not allowed on numbers but in Python 2 the leading zero
means that the number is an octal number (base eight), so 04 or 03 would mean 4 and 3 in
octal, respectively, but 08 would be invalid as it is not a valid octal number. Valid print function
for this would be
>>> print(1)
1
>>> For a integer or represent the value as a string
>>> print ('01')
01
>>>
5) >>> 1/(2/3)
1.5
>>> This is just a arithmetic operation that follows simple rules. First 2/3 is divided then 1 gets
divided by the result. >>> 2/3
0.6666666666666666
>>> 1/0.66
1.5151515151515151
>>> The result is rounded to two digits in a float in the first case. In the second case default
result has 16 digits.
310 words
Great job, your explanation was good and clear, keep going.
10 words
/
Permalink Show parent
Permalink Show parent
Dear Chester!
Thank you for your job, everything is clear and true. To be precise - octal numbers are
allowed in Py3 but the syntax was changed. Leading zeroes in numbers are marked as a
mistake to ensure that only new syntax will be used.
44 words
>>> print 'Hello, World!' -> It returned an error because I’m using python 3. If I was using python
2, it would return “Hello, World” on the output.
>>> print(01) -> Syntax error: Invalid token - It returned an error because this is the wrong way
to print leading zeros in the output.
>>> 1/(2/3) -> 1.5 - It returned the correct result of the operation.
77 words
I think we were supposed to paste the outputs into our posts but other than that really
nice explanations. Good job also using both programs to see the differences for your self.
/
I'd assume we got the same outputs, but I cant really tell for some of them.
I d assume we got the same outputs, but I cant really tell for some of them.
48 words
1. >>> print'Helo,World!'
SyntaxError: invalid syntax
There is SyntaxError:invalid syntax because parentheses are missing. Correct format is as
below.
>>> print('Hello,World!')
Hello,World!
2. >>> 1/2
0.5
The operator / performs as divison . So 1/2 is basically 0.5
3. >>> type(1/2)
When we run the syntax , we got the no error . 1/2 is basically 0.5 , so its a float
4. >>> print(01)
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers
>>> print (1)
1
Its error because there is 0 infront of integer(1)but when we remove 0 it prints
5. >>> 1/(2/3)
1.5
first 2/3 is 0.67 and later 1 divided by 0.67 we get the 1.5 because float is written with . in the
middle
131 words
Good job not only explaining but also correcting each line of code. We both got the same
results. Nice post.
20 words
/