i have my code all the way complete except one syntax error
code(
import math
f=open("101primes.txt")
primes=[]
for line in f:
primes.append(int(line))
thelist=[2692493, 2692503, 4632703, 8767843, 7982119, 7983121,
13065521 ,
11505341 ,11505343 ,14123649 ,14123651]
for i in thelist:
oof=1
TV=int(math.sqrt(i))
for x in primes:
if(x>TV):
break
elif(i%x == 0):
oof=0
break
if(oof):
print str(i)+ "is a prime number"
else:
print str(i)+ "is not a prime number"
)
import math
f=open("101primes.txt")
primes=[]
for line in f:
primes.append(int(line))
thelist=[2692493, 2692503, 4632703, 8767843, 7982119, 7983121,
13065521 ,
11505341 ,11505343 ,14123649 ,14123651]
for i in thelist:
oof=1
TV=int(math.sqrt(i))
for x in primes:
if(x>TV):
break
elif(i%x == 0):
oof=0
break
if(oof):
print (str(i)+ "is a prime number")
else:
print (str(i)+ "is not a prime number")
---------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPLANATION:
Basically you were making a mistake in your code it was not that big the print statement requires BRACKETS to be put on the whole statement. I have marked the code as bold where you were making mistake.
PLEASE GIVE A THUMBS UP
IF YOU ANY QUERIES LET ME KNOW IN THE COMMENTS
i have my code all the way complete except one syntax error code( import math f=open("101primes.txt")...
I highlighted the row I am having a constant syntax error issue. import struct record = open("block.dd") def open(file): try: record = open(block.dd, "rb") record = bytearray() record = file.read(2048) file.close() finally: return record def search_record(x, y): try: search = x[y] except(IOError): print('Cannot search') else: return search status = 0x1BE if status == 0x80: print("Status: Active") else: print("Status: Not active") ptype = record[0x1BE+4] print("The partition type is " + str(search_file(record, ptype)) address = struct.unpack("<i", record[0x1BE+8:0x1BE+12]) print("Address of the first sector...
I am completing a rental car project in python. I am having syntax errors returned. currently on line 47 of my code "averageDayMiles = totalMiles/daysRented" my entire code is as follows: #input variable rentalCode = input("(B)udget , (D)aily , (W)eekly rental? \n") if(rentalCode == "B"): rentalPeriod = int(input("Number of hours rented?\n")) if(rentalCode == "D"): rentalPeriod = int(input("Number of days rented?\n")) if(rentalCode == "W"): rentalPeriod = int(input("Number of weeks rented?\n")) rentalPeriod = daysRented return rentalCode , rentalPeriod budget_charge = 40.00 daily_charge...
FIX CODE-- import random number=random.randint ('1', 'another number') print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1, 5) print("You will have " + str(guess) + " guesses.") YourNumber = ??? unusedguesses=int(guess) while unusedguesses < guess: if int(YourNumber) == number: print("YAY, You have guessed my number") else: unusedguesses=int(guess)-1 if unusedguesses == 0: break else: print("Try again!") print("The number was ", str(number))
Is there another way to write this code in python? def processFile(): inFile = open("inputFile.txt") sumOfNumbers = 0 count = 0 minimum = 0 maximum = 0 for line in inFile: n = int(line) if count == 0: minimum = n maximum = n else: if n > maximum: maximum = n if n < minimum: minimum = n count = count + 1 sumOfNumbers = sumOfNumbers + n inFile.close() avg = (int)(sumOfNumbers / count) avg = sumOfNumbers / count...
Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...
I am having trouble with my Python code in this dictionary and
pickle program. Here is my code but it is not running as i am
receiving synthax error on the second line.
class Student:
def__init__(self,id,name,midterm,final):
self.id=id
self.name=name
self.midterm=midterm
self.final=final
def calculate_grade(self):
self.avg=(self.midterm+self.final)/2
if self.avg>=60 and self.avg<=80:
self.g='A'
elif self.avg>80 and self.avg<=100:
self.g='A+'
elif self.avg<60 and self.avg>=40:
self.g='B'
else:
self.g='C'
def getdata(self):
return self.id,self.name.self.midterm,self.final,self.g
CIT101 = {}
CIT101["123"] = Student("123", "smith, john", 78, 86)
CIT101["124"] = Student("124", "tom, alter", 50,...
For my computer class I have to create a program that deals with
making and searching tweets. I am done with the program but keep
getting the error below when I try the first option in the shell.
Can someone please explain this error and show me how to fix it in
my code below? Thanks!
twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
I have written code to display a temp reading on a RPI to an LCD screen in python. I am required to have the data be sent to a JSON file and am having trouble modifying this to happen. I know I import JSON but then do I create a data set or can I pull it directly from the data that is being collected. Below is my code. from grovepi import * from grove_rgb_lcd import * from time import...
Please help to resolve my error. This Java code is supposed to evaluate one line equation of the form X Operator =Z where X is any name of a variable and Y and Z are integers By user in equation solver window. Currently the code executes expressions such as Y Operator(+,-,*,/) Z package Equations; /** * This program evaluates arithmetic expressions */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.StringTokenizer; public class EquationSolver extends JFrame implements ActionListener { private JTextField...