PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 15, 2022

[FIXED] How do I get a certain response from a certain input

 August 15, 2022     input, output, python     No comments   

Issue

Example = If the person types in 20, say that 20 was NOT the correct answer My current code that I'm trying to work with is:

response = (input ('Type a number'))
if response == '5':
print('5 was the correct answer')

Solution

Add an else and use f-strings to insert the user's input into your response:

answer = input('Type a number')
if answer == '5':
    print(f'{answer} was the correct answer')
else:
    print(f'{answer} was NOT the correct answer')


Answered By - Samwise
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing