user-input

How can I count occurrences of words specified in an array in Python?

How can I count occurrences of words specified in an array in Python? Question: I am working on a small program in which the user enters text and I would like to check how many times the given words occur in the given input. # Read user input print("Input your code: n") user_input = sys.stdin.read() …

Total answers: 1

Python input() function is skipping a line on the first input

Python input() function is skipping a line on the first input Question: I’am trying to make a text-adventure but i encountered a weird problem that I can’t solve. I dont know what I’ve changed because I know it worked at some point but the startinput doesn’t take the first user input and skipps to the …

Total answers: 2

How to fix dictionary not counting duplicate numbers as new entries

How to fix dictionary not counting duplicate numbers as new entries Question: Currently, my code is as follows: max_length = 3 squares = {} while len(squares) < max_length: print("Enter the side length of the square:") side = input() side = int(side) Perimeter = side*4 Area = side*side squares[Area] = Perimeter And the problem with this …

Total answers: 3

Why is infinite inputting of a variable happening in Python?

Why is infinite inputting of a variable happening in Python? Question: num = int(input()) evenCounter = 0 while num != 0: if num % 2 == 0: evenCounter += 1 print(evenCounter) Maybe this is sort of silly question, but I really can’t figure out why does inifite input of the variable happen here. The console …

Total answers: 1

How can I write 2 input to python subprocess

How can I write 2 input to python subprocess Question: I am trying to use subprocess library. The file that I am trying to run with subprocess: a = input() print(a) Here is what I tried: import subprocess p = subprocess.Popen([‘python’, ‘registration.py’], encoding="Utf8") p.communicate(input="11") It worked very well. Then I tried to use multiple inputs: …

Total answers: 1

check if user input contains set element in python

check if user input contains set element in python Question: spam = {"make a lot of money","buy now","subscribe this","click this"} text = input("Enter your text: ") if (text in spam): print("It is spam") else: print("it is not spam") this code snippet is not working for the entered input ex – text = "make a lot …

Total answers: 1