please i'm having problems resolving a function about a program in Visual Fox Pro.
I need to make a rounding down every 20 minutes in decimal.
For example: if i recive 19 minutes (0.316) y need return 0 minutes.
if i get between 0-19 minutes, return 0 minutes
if i get between 20-39 minutes, return 20 minutes
if i get between 40-59 minutes, return 40 minutes
if i get between 60-79 minutes, return 60 minutes
i was thinking use ROUND() but i don't know how because "Round" Approaches to the nearest decimal.
thanks in advance.
roundedMinutes = Floor( m.myMinute / 20 ) * 20
For example:
Create Cursor SampleMin (minutes i, rounded i)
Local ix
For ix = 1 To 600
Insert Into SampleMin ;
(minutes, rounded) ;
values ;
(m.ix, Floor(m.ix/20) * 20)
Endfor
Locate
Browse
Here's a small prg I made that will hopefully help you or at least start you in the right direction.
lnStart = 0
lnEnd = 20
lnReceivedMinutes = 500
llNotDone = .T.
IF lnReceivedMinutes > 0
DO WHILE llNotDone
IF BETWEEN(lnReceivedMinutes, lnStart, lnEnd)
llNotDone = .F.
MESSAGEBOX(ALLTRIM(STR(lnStart)) + " Minutes")
ELSE
lnStart = lnStart + 20
lnEnd = lnEnd + 20
ENDIF
ENDDO
ENDIF
I check to see if the value received is between my lnStart and lnEnd. If it is not then I check for the next 20 minutes.
Cetin Basoz gave correct answer
roundedMinutes = Floor( m.myMinute / 20 ) * 20
I have checked myself
Related
I am trying to write a program for adding the natural numbers from 1 to n (1 + 2 + 3 + ... + n). However, the sum appears 1 when I use if statement. And when I use for-next statement there is a syntax error that I don't understand.
if:
30 let s = 0
40 let i = 1
50 s = s + i
60 i = i + 1
70 if i<=n, then goto 50
80 print s
for-next:
30 let i, s
40 s = 0
50 for i = 1 to n
60 s = s + i
70 next i
80 print n
When I take n = 10, the if statement code gives a result of 1, but it should be 55.
When I try to use the for-next statement, it gives no result saying that there is a syntax error in 30.
Why is this happening?
The following code works in this online Basic interpreter.
10 let n = 100
30 let s = 0
40 let i = 1
50 s = s + i
60 i = i + 1
70 if i <= n then goto 50 endif
80 print s
I initialised n on the line labelled 10, removed the comma on the line labelled 70 and added an endif on the same line.
This is the for-next version:
30 let n = 100
40 let s = 0
50 for i = 1 to n
60 s = s + i
70 next i
80 print s
(btw, the sum of the first n natural numbers is n(n+1)/2:
10 let n = 100
20 let s = n * (n + 1) / 2
30 print s
)
Why is this happening? Where am I mistaking?
30 let s = 0
40 let i = 1
50 s = s + i
60 i = i + 1
70 if i<=n, then goto 50
80 print s
Fix #1: Initialize variable 'n':
20 let n = 10
Fix #2: Remove comma from line 70:
70 if i<=n then goto 50
30 let i, s
40 s = 0
50 for i = 1 to n
60 s = s + i
70 next i
80 print n
Fix #1: Initialize variable 'n':
30 let n = 10
Fix #2: Print 's' instead of 'n':
80 print s
10 cls
20 let x=1
30 for x=1 to 100
40 print x
50 next x
60 end
Hey I'm making this game and i need a 1 or more second delay?
Got any ideas?
heres where i need a delay in between tx3 = 1000 and cheesyx = 1000.
if x < 300 and y < 300 and not duringfight:
win.blit(cheesyt3, (tx3, ty3))
if x < 250 and y < 250 and not duringfight:
tx3 = 1000
cheesyx = 1000
if cheesyx == 1000:
deathx -= 5
if deathx == 600:
deathx += 5
deathmove = False
wmx = 1000
win.blit(deathtext, (dtext, 400))
if x > 400:
dtext = 1000
win.blit(deathhanpup, (deathx, deathy))
deathy = 1000
Since time.sleep doesnt work that well with pygame, you can use the time module to compare the current time with the last execution, and execute your code in a (event)loop only after more than a second has passed.
import time
last_execution = time.time()
if time.time() - last_execution > 1:
last_execution = time.time
execute_code_you_want()
Pygame time
In pygame, time.sleep(1) doesn't work well, so you could do pygame.time.delay(1), that works fine.
Link: https://www.pygame.org/docs/ref/time.html#pygame.time.delay.
~Why the hell has this had down votes.... you people are weird!
Ok so this is a very simply HTML5 and jQuery and PHP game. Sorry to the people who have answered, I forgot to say this is a php script, i have updated here to reflect.
the first level takes 1 minute. Every level after that takes an extra 10 seconds than the last level. like so;
level 1 = 60 seconds
level 2 = 70 seconds
level 3 = 80 seconds
level 4 = 90 seconds
and so on infinitely.
I need an equation that can figure out what is the total amount of seconds played based on the users level.
level = n
i started with (n * 10) + (n * 60) but soon realized that that doesn't account for the last level already being 10 seconds longer than the last. I have temporarily fixed it using a function calling a foreach loop stopping at the level number and returning the value. but i really want an actual equation.
SO i know you wont let me down :-)
Thanks in advance.
this is what i am using;
function getnumberofsecondsfromlevel($level){
$lastlevelseconds = 60;
while($counter < $level){
$totalseconds = $lastlevelseconds+$totalseconds;
$lastlevelseconds = $lastlevelseconds + 10;
$counter++;
}
return $totalseconds;
}
$level = $_SESSION['**hidden**']['thelevel'];
$totaldureationinseconds = getnumberofsecondsfromlevel($level);
but i want to replace with an actual equation
like so;(of course this is wrong, this is just the example of the format i want it in i.e an equation)
$n = $_SESSION['**hidden**']['thelevel']; (level to get total value of
in seconds)
$s = 60; (start level)
$totaldureationinseconds = ($n * 10) + ($s * $n);
SOLVED by Gopalkrishna Narayan Prabhu :-)
$totalseconds = 60 * $level + 5* (($level-1) * $level);
var total_secs = 0;
for(var i = 1; i<= n ;i++){
total_secs = total_secs + (i*10) + 50;
}
for n= 1, total_secs = 0 + 10 + 50 = 60
for n= 2, total_secs = 60 + 20 + 50 = 130
and so on...
For a single equation:
var n = level_number;
total_secs = 60 * n + 5* ((n-1) * n);
Hope this helps.
It seems as though you're justing looking for the equation
60 + ((levelN - 1) * 10)
Where levelN is the current level, starting at 1. If you make the first level 0, you can get rid of the - 1 part and make it just
60 + (levelN * 10)
Thought process:
What's the base/first number? What's the lowest it can ever be? 60. That means your equation will start with
60 + ...
Every time you increase the level, you add 10, so at some point you'll need something like levelN * 10. Then, it's just some fiddling. In those case, since you don't add any on the first left, and the first level is level 1, you just need to subtract 1 from the level number to fix that.
You can solve this with a really simple mathematical phrase (with factorial).
((n-1)! * 10) + (60 * n)
n is the level ofcourse.
I am a beginner to Python so I do not know a lot of terms or anything really. Can I ask on how to convert minutes to hours and minutes
EX: 75 minutes ->0 days, 1 hour, 15 minutes
print("Welcome to the Scheduler!")
print("What is your name?")
name = input()
print("How many chocolates are there in the order?")
chocolates = input()
print("How many chocolate cakes are there in the order?")
chocolate_cakes = input()
print("How many chocolate ice creams are in the order?")
chocolate_ice_creams = input()
total_time = float(chocolates) + float(chocolate_cakes) + float(chocolate_ice_creams)
print("Total Time:")
print("How many minutes do you have before the order is due?")
minutes = input()
extra_time = float(minutes) - float(total_time)
print("Your extra time for this order is", extra_time)
time = extra_time // 60
print("Thank you,", name)
Well if you're given an input in minutes that is greater than equal to 1440 minutes, then you have at least a day. So to handle this (and the other aspects of time) we can use modulus (%).
days = 0
hours = 0
mins = 0
time = given_number_of_minutes
days = time / 1440
leftover_minutes = time % 1440
hours = leftover_minutes / 60
mins = time - (days*1440) - (hours*60)
print(str(days) + " days, " + str(hours) + " hours, " + str(mins) + " mins. ")
This should work.
# Python Program to Convert seconds
# into hours, minutes and seconds
def convert(seconds):
seconds = seconds % (24 * 3600)
hour = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d:%02d" % (hour, minutes, seconds)
# Driver program
n = 12345
print(convert(n))
method = a
import datetime
str(datetime.timedelta(seconds=666))
'0:11:06'
method = b
def convert(seconds):
seconds = seconds % (24 * 3600)
hour = seconds // 3600
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%d:%02d:%02d" % (hour, minutes, seconds)
from datetime import datetime
day = minutes = hours = 0
day = datetime.now ()
day = day.day
minutes = datetime.now ()
minutes = minutes.minute
hours = datetime.now ()
hours = hours.hour
print ("It's day" + str (day) + "and it's" + str (minutes) + "minutes and" + str (hours) + "hours.")
This code above does not work I started to make my own version of how this code could help you remember I am an amateur is true
from datetime import datetime
day = minutes = hours = 0
time = datetime.now().minute
days = time / 1440
leftover_minutes = time % 1440
hours = leftover_minutes / 60
mins = time - (days*1440) - (hours*60)
print(str(days) + " days, " + str(hours) + " hours, " + str(mins) + " mins. ")
You actually have to round down values in order to get integers.
import math
def transform_minutes(total_minutes):
days = math.floor(total_minutes / (24*60))
leftover_minutes = total_minutes % (24*60)
hours = math.floor(leftover_minutes / 60)
mins = total_minutes - (days*1440) - (hours*60)
#out format = "days-hours:minutes:seconds"
out = '{}-{}:{}:00'.format(days, hours, mins)
return out
n = int (input())
day = int (n // 1440)
hours = int (n % 1440) // 60
mins = int (n % 1440) % 60
print(day)
print(hours)
print(mins)
Someone does 20 Hours 42 Minutes & 16 Seconds in one shift totaling 74536 seconds.
How do I get the hours from number of seconds the person has done for that shift?
20 * 60 * 60 = 72000
42 * 60 = 2520
16 = 16
+ -----
Total = 74536
____________________________
Total % 60 = Seconds (16)
Total % ? = Minutes (42)
Total % ? = Hours (20)
Tried 84600 already; turns out when a number is lower the modulus, it really is not very helpful, and something I am going to have to catch should someone only sign in for a few seconds ...
You need to use both modulus and division:
t = seconds_in_shift;
secs = t % 60;
t /= 60;
mins = t % 60;
t /= 60;
hour = t;
Or:
secs = ttime % 60;
mins = (ttime / 60) % 60;
hour = ttime / 3600;
One other option uses the div() function from Standard C (<stdlib.h>):
div_t v1 = div(ttime, 60);
div_t v2 = div(v1.quot, 60);
After that, v1.rem contains the seconds; v2.rem contains the minutes, and v2.quot contains the hours based on the number of seconds originally in ttime.
Based on Jonathan's reply, I believe the accurate answer should be this…
$total_time = 61000;
$sec = $total_time % 60;
$total_time = ($total_time - $sec) / 60;
$min = $total_time % 60;
$hour = ($total_time - $min) / 60;
echo "$hour hours, $min minutes and $sec seconds";
But if your server has PHP7 installed, you can use the intdiv() function. An integer division in which the remainder is discarded.
// $hour = ($total_time - $min) / 60; old code but still works
$hour = intdiv($total_time, 60); // PHP7 and above code