[Tutor] How to manipulate a user's input twice in one statement
Goran Ikac
goranikac65 at gmail.com
Wed May 17 02:25:30 EDT 2023
I'd like to manipulate an user's input using a method. The argument for
that method depends on the value of the user's input. In my previous
question, I used a slice of the input as an example of a value that depends
on the value of the input.
I'm aware that I can get the result this way:
>>> user_input = input('Please, type a word: ')
>>> to_remove = user_input[1:] # The value of the slice depends
of the value of the input.
>>> result = user_input.removesuffix(to_remove)
# The result depends on both the value of the input, and the value of the
slice that was applied to the input.
Or this way:
>>> user_input = input('Please, type a word: ')
>>> result = user_input.removesuffix(user_input[1:])
I was curious if I could get the result (that depends on both the value of
the input, and the value of the slice that was applied to the input)
without assigning the input to a variable first. Perhaps I could ask the
same question this way:
>>> user_input = int(input('Please, type a number: '))
>>> value_to_use = 2 + user_input # This value depends of the value
of the input.
>>> result = 3 * value_to_use
# The result depends on both the input, and the output of the expression
that used the input as an operand.
Or this way:
>>> user_input = int(input('Please, type a number: '))
>>> result = 3 * (2 + user_input)
That could be written:
>>> result = 3 * (2 + int(input('Please, type a number: '))
But, if I need to manipulate the value (that depends on the value of the
input) by a method, not by an operand or by a function, can I do it without
assigning that value or/and the value of the input to a variable?
Perhaps not?
People, I'm learning, not trying to write a useful program, yet. Last time
when I asked a "pointless" question (NoneType List), I learned an important
concept from your answers, a concept that I failed to understand properly
from the textbooks. I appreciate your time very much.
Love
Goran from Croatia
More information about the Tutor
mailing list