简体   繁体   中英

How do I incorporate user input into the python code below?

So I'm just learning the basics of python in JES (image Manipulation).

I have the following code below which decreases the red by 20% in an image:

def decreaseRed(picture):
  for p in getPixels(picture):
    value=getRed(p)
    setRed(p, value 0.2)

How do I incorporate user input into this code, so that the user can input the percentage value?

Please note that I know little about Python, so some detailed answers would be amazing. Don't forget I'm using JES by the way.

I think the most obvious way is to read it from stdin, like this:

new_val = float(input('Enter new value: '))      # python 3
new_val = float(raw_input('Enter new value: '))  # python 2

So your code might look like this (remember to add some checking if the value user typed is correct):

def decreaseRed(picture): 
    for p in getPixels(picture): 
        new_val = float(raw_input('Enter new value: ')) 
        setRed(p, new_val)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM