Python Forum
I need help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I need help (/thread-4422.html)

Pages: 1 2


I need help - 777CAIN - Aug-15-2017

Is it possible to get a user to type in something like Apples and it comes back with a number eg

I type apple it comes back as 6?

If so could someone help me do it thank you!


RE: I need help - sparkz_alot - Aug-15-2017

What have you tried?


RE: I need help - 777CAIN - Aug-15-2017

(Aug-15-2017, 02:50 PM)sparkz_alot Wrote: What have you tried?

I'm new to Python and had no lessons so I have tried nothing sorry :(


RE: I need help - Bass - Aug-15-2017

HI,

Yes, it is fairly straighforward.

You could use the len function to calculate the number of characters in the word that has been inputted e.g. apple.

x = len(inputted_word)
Where x would be 5 in this case.

Or you could use an if statment to output a unique code or value if the entered word was apple.

if inputted_word == "apple":
    print("!""$%")
or you could replace certain letters in the word apple with other letters.

Let us know which of these you would like help with, or maybe you want other thoughts.

Bass


RE: I need help - 777CAIN - Aug-15-2017

Bass I want to do the 2nd one :P


RE: I need help - nilamo - Aug-15-2017

(Aug-15-2017, 02:39 PM)777CAIN Wrote: Is it possible to get a user to type in something like Apples and it comes back with a number eg

I type apple it comes back as 6?

If so could someone help me do it thank you!

Sure!
whatever_they_typed = input("Say something! ")
print(6)



RE: I need help - 777CAIN - Aug-15-2017

(Aug-15-2017, 03:40 PM)nilamo Wrote:
(Aug-15-2017, 02:39 PM)777CAIN Wrote: Is it possible to get a user to type in something like Apples and it comes back with a number eg

I type apple it comes back as 6?

If so could someone help me do it thank you!

Sure!
whatever_they_typed = input("Say something! ")
print(6)

Every time they type something different how does it respond different like if i put apple and it says 6 and i put apple123 can it put 12 ect?


RE: I need help - sparkz_alot - Aug-15-2017

(Aug-15-2017, 03:44 PM)777CAIN Wrote: Every time they type something different how does it respond different like if i put apple and it says 6 and i put apple123 can it put 12 ect?

You could create a dictionary:
my_dict = {'apple':6, 'apple123':12, 'apple_snapple':500}
Of course, you would need to know every possible input a user might enter.  You really need to make your question more specific as to what you are trying to do.


RE: I need help - 777CAIN - Aug-15-2017

(Aug-15-2017, 03:53 PM)sparkz_alot Wrote:
(Aug-15-2017, 03:44 PM)777CAIN Wrote: Every time they type something different how does it respond different like if i put apple and it says 6 and i put apple123 can it put 12 ect?

You could create a dictionary:
my_dict = {'apple':6, 'apple123':12, 'apple_snapple':500}
Of course, you would need to know every possible input a user might enter.  You really need to make your question more specific as to what you are trying to do.

I'm trying to do a aircraft CI database where people can put in a airline eg Ryanair and it will say there CI so 6. and every CI if different to every airplane so I want it to do that if possible.


RE: I need help - nilamo - Aug-15-2017

How do you know that a Ryanair is a 6?

Unless you put it somewhere in your program (or if it's standardized, use a library/service), how do you expect python to know that whatever a "Ryanair" is means whatever meaning you attach to "6"?  To python, they're just unrelated strings/numbers.