简体   繁体   中英

Subtracting depending on an if function in python

Convert the character into its ASCII code

Add the ASCII code to the offset factor calculated in Task 4.

If the result is bigger than 126 then subtract 94 so it is a valid ASCII code.

Convert the result into its equivalent ASCII character.

I need to subtract 44 from an if function but I'm not really sure how to do it. My code so far is:

      a = text
      sev=[ ord(x) for x in a ]
      sev= sev + offsetFactor
      if sev>126
      next sev-44

Would I use the next function and if not what function would is use?

I think you must do

  a = text
  sev=[ ord(x) + offsetFactor for x in a]
  sev = [ x - 94 for x in sev if x > 126]
a = "Kitty Bates"
sev=[ ord(x) for x in a ]
S= sum(sev)

while(1):
    try:
        print chr(S)
        break   # will break on valid ASCII

    except:
        S= S-44

output Click here

Ф

As per your req

a = "Kitty Bates"
sev=[ ord(x) for x in a ]
S= sum(sev)

while(1):
    try:
        if(S>126):
            0/0
        print chr(S)
        break  #will break if ASCII is below 126

    except:
        S= S-44

output

\

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