Answer to Question #291095 in Python for seb

Question #291095
  1. Input two integers in one single line. The first inputted integer must be within 0-9 only.
  2. Using loops, identify if the first inputted integer (0-9) is present in the second inputted integer. If it is found, print "Yes". Otherwise, print "No".
  3. Tip #1: If the number is already found even without reaching the end of the loop, use the break keyword to exit the loop early for a more efficient code.
  4. Tip #2: Create a "flag" variable outside the loop. A flag variable will be like a light switch which will only have two states: on and off. Hence, it will just be an integer variable which you, the programmer, will make sure that it will only hold two values: 0 and 1. 0 will represent false while 1 will represent true. In this problem, this flag variable will track if we have found the digit inside the other inputted integer. Hence, initially set this to 0 because before you make the loop, you haven't found yet the digit.
1
Expert's answer
2022-01-27T09:27:16-0500
Flag=1
while(Flag):
    s = str(input("Enter two numbers separated by space: "))
    s = s.split(" ")
    a = int(s[0])
    b = int(s[1])
    Flag=0
    if(a<0 or a >9):
        Flag=1
        print("NO")
    else:
        print("YES")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS