[issue39476] Not convinced with the dynamic data type assignment

2020-01-28 Thread Sushma


Sushma  added the comment:

Thank you

On Tue, Jan 28, 2020, 6:30 PM Steven D'Aprano 
wrote:

>
> Steven D'Aprano  added the comment:
>
> The "num" variable is not a number, it *is* a string. Just because you
> call it "num" doesn't magically turn it into a number. The `input` function
> returns a string.
>
> You might be thinking of Python 2.7 where `input` automatically evaluated
> the string as Python code. Python 3 does not do that. If you want to
> convert the string result of `input` to be a float or an int or some other
> type, you need to call the `float` or `int` functions.
>
> --
> nosy: +steven.daprano
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39476] Not convinced with the dynamic data type assignment

2020-01-28 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

Sushma, asking about the exception message on python-list was the right thing 
to do.  You should have waited for the answers you got there.  At this point, 
bugs in basic python operations are extremely rare.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39476] Not convinced with the dynamic data type assignment

2020-01-28 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

The "num" variable is not a number, it *is* a string. Just because you call it 
"num" doesn't magically turn it into a number. The `input` function returns a 
string.

You might be thinking of Python 2.7 where `input` automatically evaluated the 
string as Python code. Python 3 does not do that. If you want to convert the 
string result of `input` to be a float or an int or some other type, you need 
to call the `float` or `int` functions.

--
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39476] Not convinced with the dynamic data type assignment

2020-01-28 Thread Sushma


New submission from Sushma :

Hi 

Please find below example and the compiler error,

when i'm assigning value dynamically and when we comparing in "if" loop it is 
throwing compiler error. It should not throw error it should assign and act as 
int why it is thinking as string.
Code Snippet:
print("Hello World")

num = input("Enter number ")

print(num)

if(num%3 == 0):
num+=num
print(num)

Output in Console:
Hello World
Enter number 15
15
Traceback (most recent call last):
File "main.py", line 15, in 
   if(num%3 == 0):
TypeError: not all arguments converted during string formatting

--
messages: 360865
nosy: Sush0907
priority: normal
severity: normal
status: open
title: Not convinced with the dynamic data type assignment
type: compile error
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com