skip to Main Content

My madlib will run in the terminal, but when I input things for verbs and adjectives it doesn’t run with them in. Please help.

adj = input(“adjective”) 
verb= input(“verb”)
Madlib= “I love to {verb} code, it can become a {adj} skill”
Print(Madlib)

It comes out in the terminal of visual studio code correctly, it just doesn’t work after I put stuff in for adjectives and verb

3

Answers


  1. you should use f-string and try this way:

    adj = input("adjective: ")
    verb= input("verb: ")
    Madlib= f"I love to {verb} code, it can become a {adj} skill"
    print(Madlib)
    

    output:

    adjective: great
    verb: do
    I love to do code, it can become a great skill
    
    Login or Signup to reply.
  2. Begin your string (the text surrounded by ") with f.

    So, your code should be

    adj = input(“adjective”) 
    verb= input(“verb”)
    Madlib= f“I love to {verb} code, it can become a {adj} skill”
    Print(Madlib)
    

    It is also good practice to begin variables with a lowercase letter (e.g., Madlib => madlib).

    Login or Signup to reply.
  3. In Python it is not the same thing as we do in Javascript, you either add an "f" before the quotes, or you can simply concatenate strings:

    madlib = 'I love to ' + verb + ' code, it can become a ' + adj + ' skill'
    

    PS: In Python, variables’ first letter should be in lowercase.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search