I am getting error in that BREAK . why od i get this error - break

age = int(input("write your age honestly: "))
if age>=18:
break
print("You are eligible to vote")
else:
print("You are not eligible to vote")
agreement = input("If you are agree write OK: ")
if agreement=="ok":
print("All set vote carefully ")
else:
print("....")

Related

Conditional Handling in R

I've been trying to create an error message when the ouput entered is wrong, for example, in this code instead of entering 4 digits number, it is entered a character.
I keep receiving an error. Any tips?
get_age <- function() {
yob <- readline("Please enter your year of birth: ")
age <- 2022 - as.numeric(yob)
return(age)
}
if (get_age != as.numeric(yob)) {
withCallingHandlers(
warning = function(cnd){
readline("This is not a number. Please, try again.")
},
print("please, enter a numerical value"),
return(get_age())
)
}

My discord bot keeps getting disconnected for some reason

I haven't changed my bot in weeks and for some reason I would get an error message like this every day for the past 5 or so days https://imgur.com/VCLx2kv
I don't think the error is caused by my code besides the whole loop thing which I don't know how to fix and it hasn't caused me any problems before, but if you're curious about that part I have the part of code that causes that issue below
I already tried regenerating my token.
#client.event
async def dead_check():
i = 1
d = datetime.now()
date = str(d.strftime("%Y-%m-%d"))
server = client.get_server(id = '105388450575859712')
while i == 1:
async for message in client.logs_from(discord.Object(id='561667365927124992'), limit=9999999):
if date in message.content:
usid = message.content.split('=')
usid1 = usid[1].split(' ')
count = message.content.split('#')
cd = message.content.split('?')
ev = cd[1]
if ev == '00':
number = 0
elif ev == '01':
number = 1
elif ev == '10':
number = 2
elif ev == '11':
number = 3
name = count[0]
await client.send_message(discord.Object(id='339182193911922689'), '#here\n' + name + ' has reached the deadline for the **FRICKLING** program.\nThe user has attended ' + str(number) + ' events.')
async for message in client.logs_from(discord.Object(id='567328773922619392'), limit=9999):
if date in message.content and message.reactions:
usid = message.content.split(' ')
user=await client.get_user_info(usid[0])
await client.send_message(discord.Object(id='567771853796540465'), user.mention + ' needs to be paid, if you have already paid him - react with :HYPERS:')
await client.delete_message(message)
await asyncio.sleep(60*60*24)
#client.event
async def on_ready():
await client.change_presence(game=Game(name='with nuclear waste'))
print('Ready, bitch')
asyncio.get_event_loop().run_until_complete(dead_check())
Have you tried reducing the limit of those logs_from calls? 9999999 is a pretty big number, and it may have slowed things down enough that the heartbeat isn't being sent at the proper times. You should also sanitize that image of the error message, it contains your bot token.
Credit to Patrick Haugh, but I wanted to close this thread and he didnt post it as an answer

How to get r to read 'date taken' of a JPG file

I could use some help performing a database correction, in regards to date and time of pictures were taken.
Essentially, the research we perform entails taking many pictures and entering the picture information into a database (we automated this with Microsoft Access). However, I performed a random check of our database and found that several dates and times of the photos were incorrect, and I am attempting to correct this via R as I was unable to correct it via Access.
What I need to do is to is write a script that reads these data, and compiles a list of the date taken information for all photos (there are several thousand). So far the best thing that I've found is
file.info(list.files(
"E:/Whatcom Creek Project/Data/Seal photos/Discovery/Catalog/Phoca vitulina",
recursive = T))
However this returns a list of NA NA for all information. Also, if I manually select one image to run file.info on, it doesn't return date taken (see the picture for the data I am attempting to retrieve)
If anyone has any suggestions I am all ears. Thanks in advance!!
-Ian
enter image description here
maybe still of any use?
i saw this message. I solved this a long time ago (2011) with a very basic VB6 code. The job is still working, but it is not applicable to all '.jpg files'. It depends with what camera the picture has been taken, but mostly pictures taken from a smartphone and classic camera's are returning the date the picture has been taken (not usable for whatsapp images or edited images).
The code is here below, and it is very basic code (but i hope it still can help or give idea's, and ... any new idea's are welcome too) :
'Reading of "Date Picture Taken" from .jpg file
'-----------------------------------------------
Debug.Print ">>>>>==== Start Read of .jpg-file ===== "; Date; " ===== "; Time; " ====<<<<<"
X = 0
DatePictureTaken = ""
TimePictureTaken = ""
FOUNDdatum = False
SWdatum = False
TELdatum = 0
Foto = FOLDER & "\" & tabFileName(FotoNr)
Open Foto For Binary Access Read As #1
'get startposition of the field "date picture taken"
Do
X = X + 1
Get #1, X, MyByte ': Debug.Print Chr(MyByte);
DoEvents
If Chr(MyByte) = ":" Then
'Debug.Print
SWdatum = True
Get #1, X + 3, MyByte
'Debug.Print "x+03="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+03="; Chr(MyByte)
Get #1, X + 9, MyByte
'Debug.Print "x+09="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+09="; Chr(MyByte)
Get #1, X + 12, MyByte
'Debug.Print "x+12="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+12="; Chr(MyByte)
'if a ':' is on the 3 locations (found above) then it is a date!
If SWdatum _
Then
TELdatum = TELdatum + 1
End If
'the 3e date is the date the picture has been taken
If TELdatum = 3 _
Then
FOUNDdatum = True
X = X - 4
Exit Do
End If
X = X + 12
End If
Loop Until EOF(1) 'Or X = 32765
If FOUNDdatum = False Then Close 1: End
BPdatum = X
EPdatum = X + 9
BPuur = X + 11
EPuur = X + 15
For X = BPdatum To EPdatum
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
DatePictureTaken = DatePictureTaken & Chr(MyByte)
End If
Next X
For X = BPuur To EPuur
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
TimePictureTaken = TimePictureTaken & Chr(MyByte)
End If
Next X
'Debug.Print "Date Picture Taken = "; DATUM
tbxDatum.Text = DatePictureTaken
tbxUur.Text = TimePictureTaken
Close 1
End Sub

Getting data off Metacritic; arguments imply differing number of rows?

I'm relatively new at this, so I'm just practicing my coding. I'm trying to get data off of Metacritic (just titles and scores), and here's my code:
library(rvest)
library(httr)
datamatrix=data.frame()
for(i in 0:98) {
metascores<-as.numeric(html_text(html_nodes(
read_html(GET(paste0("http://www.metacritic.com/browse/movies/score/metascore/all?page=", i),
add_headers("User-Agent" = "myagent"))),
xpath = '//*[(#id = "mantle_skin")]//*[contains(concat( " ", #class, " " ), concat( " ", "positive", " " ))]')))
metanames<-as.character(html_text(html_nodes(
read_html(GET(paste0("http://www.metacritic.com/browse/movies/score/metascore/all?page=", i),
add_headers("User-Agent" = "myagent"))),
xpath = '//*[contains(concat( " ", #class, " " ), concat( " ", "title", " " ))]//a')))
metanamesv2<-gsub(" ", "-", metanames)
metanames.final<-gsub(":", "", metanamesv2)
data<-data.frame(metascores, metanames.final)
datamatrix<-rbind(datamatrix, data)
}
However, when I try and run this code, I get an error:
Error in data.frame(metascores, metanames.final) :
arguments imply differing number of rows: 63, 100
But this always occurs on different webpages! For example, in the beginning it would stop at page 3, but then I reset everything and it stopped at page 18, and now page 45 (my datamatrix has 4500 observations of 2 variables, whereas before it would have 300 and 1800.) In other words, it seems to have fixed the error occasionally and is able to pull the correct data sometimes. Why is that? Why is it not consistent? Is it the web page messing it up, or the consistent need to go back to a different link?
Please note: Feel free to assess my code! Like I said, I'm literally just starting, so I'm sure all my code is grossly inefficient. I'm also aware of the magrittr package, that's probably the next step in using this, I just wanted to test this stuff out first.
EDIT: Well...I fixed it. Kinda. Feel free to critique my code though.

Python 2.7.3 Math Flaw( 40 million is less then six hundred thousand )

SOLVED
In my program, it thinks that 40 million is less then 600,000.
Here is the code:
(Stop it after it loops 20 times)
import re
import urllib2
x = 0
d = 1
c = 1
highestmemberid = 1
highestmembercash = 4301848
while (d==1):
x = float(x + 1)
if (x==14 or x==3 or x==11 or x==13 or x==15):
x = x + 1
print x,
url = "http://www.marapets.com/profile.php?id=" + str(x)
home = opener.open(url)
matchpoint = re.compile("<td align='left' valign=middle><B style='color:#(......);'>(.*?)</B></td>")
home = home.read()
home = home
points = re.findall(matchpoint,home)
if ("http://images.marapets.com/stuff/banned.gif" in home or "This user does not exist" in home):
print "banned/dosen't exist"
else:
mp = points[0][1]
mp = mp.replace(" MP","")
mpcheck= mp.replace(",","")
mp = float(mpcheck)
if (mpcheck > highestmembercash):
highestmembercash = mpcheck
highestmemberid = x
print "richer"
else:
print "Not richer!"
print mp
print "The richest player in marapets is player id #: " + str(highestmemberid) + "Who has: " + str(highestmembercash) + " MP."
if(x == 5368561):
print "The richest player in marapets is player id #: " + str(highestmemberid) + "Who has: " + str(highestmembercash) + " MP."
What the program does is grab cash amounts from the page, and then sees if this is the highest amount. It loops about 5 million times.
mpcheck is a string, you want to check that mp > highestmembercash and assign highestmembercash = mp.

Resources