• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3526

    Source: Created with the help of AI tool

    The issue you’re encountering with None appearing in the input likely comes from how you’re using the input() and print() functions together in your Python code.

    Here’s the part of your code causing the issue:

    s = str(input(print('entry: ')))
    

    In this line, print('entry: ') executes first, printing the message “entry:”. However, print() doesn’t return any value; it returns None. Then, the input() function is called with None as its argument, which leads to Python printing None before the user input.

    That’s why you see Noneabcdef—because the None is printed right before the input is captured.

    Solution

    To fix this, you don’t need to use print() inside the input() function. You can rewrite the line like this:

    s = input('entry: ')
    

    This will print “entry:” to prompt the user, and then wait for their input without returning None.

    Here’s your corrected code:

    s = input('entry: ')
    numofvowels = 0
    numCons = 0
    
    for char in s:
    if char in 'aeiou':
    numofvowels += 1
    else:
    numCons += 1
    
    print('number of vowels: ' + str(numofvowels))
    

    This should work without printing None, and you’ll be able to enter words without that issue.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Scroll to Top