Python Forum
Python-Can I get some help with this ModuleError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-Can I get some help with this ModuleError
#1
The program works fine if I run it on Pycham but if I try to run it on IDLE 3.9 it displays an error. I already try the (pip install k) but It don't work or maybe I no typing it correctly? or in the right place.


import random
import k as k

def linearSearch(list1,k):
    i=0
    n=len(list1)


    for i in range(n):
        print("index: ",i)
        print("comparing ",list1[i]," with ",k)
        if(list1[i]==k):
            print("\n",k," Found at index\n :",i)
            break
    else:
        print("\n",k," Not Found\n\n")


def randomListGenerate(len):
    list1=[]
    for i in range(len):
        k = random.randint(1,50)
        list1=list1+[k]
    return list1

k = random.randint(1,50)
list1 = randomListGenerate(10)
print("List is :",list1)
print("Element to search: ",k)
linearSearch(list1,k)
list1 = randomListGenerate(10)
list2 = randomListGenerate(10)

print("\nList1 is :",list1)
print("List2 is:",list2)
print("\nsearching each element of list1 in list2:")
for k in list1:
    linearSearch(list2,k)
Output:
Traceback (most recent call last): File "C:/Users/Alex/Desktop/test.py", line 2, in <module> import k as k ModuleNotFoundError: No module named 'k'
Reply


Messages In This Thread
Python-Can I get some help with this ModuleError - by AlexPython - Sep-23-2022, 12:02 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020