Problem by Dictonary with Variable and Input

i am writting a code that is counting random Numbers. Everytime when i change the value in the script, everything is working. But when im changing the variable to inpu with Summe = input("YourNumber"), it is not working.

import random
import time

#MyNumber = input("YourNumber")
Summe = input("Suche deine Zahl")
for i in range(1, 101):
    RamdomNumber = random.randrange(1, 4)
    globals()[f"Number{i}"] = RamdomNumber

Dictonary = {k: v for k, v in globals().items() if not k.startswith("__")}

print({k: v for k, v in globals().items() if not k.startswith("__")})
print(sum(value == Summe for value in Dictonary.values()))
#Prozentsumme = Summe / 10
print("Deine Nummer ist:", MyNumber)
#print("Deine Nummer gab es:", Summe , "Mal")
#print("Die Wahrscheinlichkeit liegt bei:", Prozentsumme * 100 , "Prozent")

Please somebody help me!!!!

Submitted May 18th 2021 by Admin


A string will never equal an int -- if you're getting a number from input() and you want to compare it to an int value, convert it with int().

import random Summe = int(input("Suche deine Zahl"))
numbers = [random.randrange(1, 4) for _ in range(100)]
for i, n in enumerate(numbers): print(f"Number{i+1}: {n}") print(sum(value == Summe for value in numbers)) print("Deine Nummer gab es:", Summe, "Mal")

Admin | 4 months ago

Relevant Questions