Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong
#1
Hello Everyone,

I am trying my hand at coding, this is my first time attempting to write any form of code. I'm alittle confused, when I run this code I don't get the output that I expect. instead I get a "None None" response. Can someone please have a look at my code and point out where I messed up. Thanks alot

user_input=input("Please enter a lower-case letter, afterward enter a space and input a number from 1-26 \n\n")
length=len(user_input)
#Assigning the lower-case alphabet to be used in the code.
a="a"
b="b"
c="c"
d="d"
e="e"
f="f"
g="g"
h="h"
i="i"
j="j"
k="k"
l="l"
m="m"
n="n"
o="o"
p="p"
q="q"
r="r"
s="s"
t="t"
u="u"
v="v"
w="w"
x="x"
y="y"
z="z"
#Defining the lower-case alphabet for use in the code.
def lc_alphabet():
    lc=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
    for var in range(25,length):
        inp=user_input(var)
        if inp==lc[0]:
            return("Good")
        elif inp==lc[1]:
            return("Beautiful")
        elif inp==lc[2]:
            return("Amazing")
        elif inp==lc[3]:
            return("Fantastic")
        elif inp==lc[4]:
            return("Astounding")
        elif inp==lc[5]:
            return("Awesome")
        elif inp==lc[6]:
            return("Wonderful")
        elif inp==lc[7]:
            return("Trendy")
        elif inp==lc[8]:
            return("Great")
        elif inp==lc[9]:
            return("Attractive")
        elif inp==lc[10]:
            return("Interesting")
        elif inp==lc[11]:
            return("Sexy")
        elif inp==lc[12]:
            return("Sweet")
        elif inp==lc[13]:
            return("Gorgeous")
        elif inp==lc[14]:
            return("Lovely")
        elif inp==lc[15]:
            return("Inspiring")
        elif inp==lc[16]:
            return("Youthful")
        elif inp==lc[17]:
            return("Enviable")
        elif inp==lc[18]:
            return("Best")
        elif inp==lc[19]:
            return("Pleasurable")
        elif inp==lc[20]:
            return("Extraordinary")
        elif inp==lc[21]:
            return("Stupendous")
        elif inp==lc[22]:
            return("Precious")
        elif inp==lc[23]:
            return("Pretty")
        elif inp==lc[24]:
            return("Favorable")
        elif inp==lc[25]:
            return("Superb")
#Assigning the numbers to be used in the code.
n1="1"
n2="2"
n3="3"
n4="4"
n5="5"
n6="6"
n7="7"
n8="8"
n9="9"
n10="10"
n11="11"
n12="12"
n13="13"
n14="14"
n15="15"
n16="16"
n17="17"
n18="18"
n19="19"
n20="20"
n21="21"
n22="22"
n23="23"
n24="24"
n25="25"
n26="26"
#Defining the number list to be used in the code.
def num_list():
    num=["1","2","3","4","5","6","7","8","9","10","11","12","13","14",
    "15","16","17","18","19","20","21","22","23","24","25","26"]
    for var2 in range(25,length):
        inp2=user_input(var2)
        if inp2==num[0]:
            return("Intelligence")
        elif inp2==num[1]:
            return("Legs")
        elif inp2==num[2]:
            return("Arms")
        elif inp2==num[3]:
            return("Heart")
        elif inp2==num[4]:
            return("Personality")
        elif inp2==num[5]:
            return("Toes")
        elif inp2==num[6]:
            return("Hands")
        elif inp2==num[7]:
            return("Fashion sense")
        elif inp2==num[8]:
            return("Spirit")
        elif inp2==num[9]:
            return("Hair")
        elif inp2==num[10]:
            return("Mindset")
#Running out of ideas!!!!
        elif inp2==num[11]:
            return("Creativity")
        elif inp2==num[12]:
            return("Face")
        elif inp2==num[13]:
            return("Muscle definition")
        elif inp2==num[14]:
            return("Shoes")
        elif inp2==num[15]:
            return("Smile")
        elif inp2==num[16]:
            return("Jawline")
        elif inp2==num[17]:
            return("Shirt")
        elif inp2==num[18]:
            return("Posture")
        elif inp2==num[19]:
            return("Pants")
        elif inp2==num[20]:
            return("Dress")
        elif inp2==num[21]:
            return("Attitude")
        elif inp2==num[22]:
            return("Outlook")
        elif inp2==num[23]:
            return("Confidence")
        elif inp2==num[24]:
            return("Car")
        elif inp2==num[25]:
            return("Physique")
try:
    print(lc_alphabet(), num_list())
finally:
    print(lc_alphabet(), num_list())
Reply
#2
Try this:

for_letters = ["Good", "Beautiful", "Amazing", "Fantastic", "Astounding",
               "Awesome", "Wonderful", "Trendy", "Great", "Attractive",
               "Interesting", "Sexy", "Sweet", "Gorgeous", "Lovely",
               "Inspiring", "Youthful", "Enviable", "Best", "Pleasurable",
               "Extraordinary", "Stupendous", "Precious", "Pretty", "Favorable"]

user_input = input('enter number or letter or word: ')

if user_input[0].isdigit():
    idx = int(user_input)
else:
    idx = ord(user_input[0].lower()) - ord('a')

print('{}'.format(for_letters[idx]))
Output:
# Test 1 enter number or letter or word: T Pleasurable # Test 2 enter number or letter or word: Harry Trendy #Test 3 enter number or letter or word: t Pleasurable
Reply
#3
Thank you for your time. Please forgive me if this is a silly question. Which part of the code do I substitute with your suggestion?
Reply
#4
run it, and you will know. I think it's pretty much all of it.
Reply
#5
You could save some typing

from string import ascii_lowercase

a,b,c,d,e,f,g,h,i,j,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z = ascii_lowercase
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
A hacky hack hackorama. You won't do this.
[setattr(sys.modules[__name__], c, c) for c in string.ascii_lowercase]
But I do not understand the sense of having variable names from a-z assigned on module level.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
(Jul-25-2017, 10:30 PM)boxedtheropy Wrote:
user_input=input("Please enter a lower-case letter, afterward enter a space and input a number from 1-26 \n\n")

def lc_alphabet():
    inp=user_input(var)

user_input is a string. Calling it, like a function, is meaningless, and should throw an error. What are you expecting inp to be?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,387 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 2,943 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020