Category : for-loop

How to count the number of occurrences of the invalid input when the user enter the wrong input. I would like to count how many times the words "invalid input " appears. Here’s my code. Please assist me. while True: number = input("Enter a. number: ") if number.isdigit(): print("The input is valid.") else: print("Invalid input.") ..

Read more

I need to get an input of words and then print only the words that are 10 letters long. I am having a lot of trouble, not sure what is the problem exactly listofwords=input(‘Enter a list of words: ‘) list1=listofwords.split(‘,’) for element in list1: if len(element)==10: print(element) My code is not printing any words unless ..

Read more

for i in range(len(words)): ttuple=words[i] # ttuple2=words[i-1] # if ttuple[1]%ttuple2[1]!=0: # bbb=bbb+"n" fish_list = [] read_operation = open(r’C:UserspiotrPycharmProjectsimportDataryby.txt’, encoding="utf-8") lines = read_operation.readlines() for line in lines: fish_list.append(line.strip().casefold()) for fish in fish_list: print(repr(fish)) if fish in ttuple[4]: print("ccccccccccccc"+fish.strip()) print("aaaaaaaaaaa" + str(ttuple[4])) What happend here? When I compare in is like if aaa!=ttuple[4] value if fish is ..

Read more

I am trying to evaluate an integral using the trapezoidal rule for a range of n = 2^p where p= [1,2…20], to produce different values for the integral. I have tried to implement a for loop to define n and h however I get a TypeError:’list’ object cannot be interpreted as an integer. Is there ..

Read more