- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我遇到的问题是,在运行该程序时,无论如何,您输入的所有内容都计为秒,而不是您实际选择的任何单位。
__author__ = 'Exanimem'
# Homework Notifier Version 0.1.5 It works a bit better. Kind of.
import time
import threading
import webbrowser
import winsound
import ctypes
import sys
import math
import pyglet
# TO-DO
# NOTE: NOT LISTED IN ORDER OF PRIORITY
# Add months, years, decades, and centuries including system to detect what month, year, decade, and centry it is
# Add ability to remind at a specific time in a unit, like "4:50 in 1 day"
# Detect spelt out numbers as numbers
# Have that you press enter then answer
# Have message box be brought to front of the screen
# Have notifications still come when application closed
# Combine unit and digit function
# User Friendly UI?
# Allow users to input time like "4:30 PM EST"
# Autodetect timezone
# Recorded log to look back on past notifications?
# Configurable beep (with music)
# Restart function (Instead of stopping program at whatever point, have option to create new notification)
# Multiple notifications
# Test stop function further and improve
# Save notification's from last time opened
# KNOWN BUGS
# Everything counted as seconds
# Occasionally message box will not appear
HW = input("What homework should I remind you to do?")
# Enter your homework
remind = input("When would you like me to remind you of this?")
# Enter desired time
remind = float(remind)
unit = input("Will your unit be in seconds, minutes, hours, days, or weeks?")
# Enter correct unit
if unit == "seconds":
remind*1
if unit == "minutes":
remind * 60
if unit == "hours":
remind * 3600
if unit == "days":
remind * 86400
if unit == "weeks":
remind * 604800
continuous = input("Would you like to have the notification be continuous?")
print(
"You may now leave the application in the background. Closing the application and shutting down your computer will deactivate the notification you have planned.")
while continuous == "yes":
time.sleep(remind)
Freq = 2500 # Set Frequency To 2500 Hertz
Dur = 1000 # Set Duration To 1000 ms == 1 second
winsound.Beep(Freq, Dur)
print("The message box has opened, but as another reminder your homework is")
print(HW)
ctypes.windll.user32.MessageBoxW(0, HW, "Homework!!!", 1)
if input("To stop the loop and close the program, please type in 'stop'") == "stop":
break
if continuous == "no":
time.sleep(remind)
Freq = 2500 # Set Frequency To 2500 Hertz
Dur = 1000 # Set Duration To 1000 ms == 1 second
winsound.Beep(Freq, Dur)
print("The message box has opened, but as another reminder your homework is")
print(HW)
ctypes.windll.user32.MessageBoxW(0, HW, "Homework!!!", 1)
我首先认为问题是第一个 if 的缩进,但如果它是有意的,程序就会停止工作。我已经尝试解决这个问题一段时间了,但我一辈子都做不到。帮忙?
最佳答案
即使您进行了正确的计算,您也永远不会更新 remind
的值 — 这意味着您正在有效地计算一些您随后丢弃的东西。
示例
remind * 3600 # will simply calculate and discard the value
remind *= 3600 # remind = remind * 3600
if unit == "seconds"
之后的 if
的缩进级别看起来只有当 unit
相等时它们才会被评估到 “秒”
。如果您的代码中的空格实际上是为了让解释器不会以这种方式读取您的代码,那么这可能不是问题,但是它看起来很奇怪并且很容易出错。
示例
if unit == "seconds":
remind*1
if unit == "minutes": # this will only execute if "unit == "seconds"
remind * 60
if unit == "seconds":
remind *= 1
if unit == "minutes":
remind *= 60
在您当前进行“计算并丢弃”舞蹈的每一点上,更新代码以便您实际存储计算值——使其可供将来使用。
同时修复缩进级别,使其看起来不再像您在使用嵌套的 if 条件。
if unit == "seconds":
remind *= 1 # useless
if unit == "minutes":
remind *= 60
if unit == "hours":
remind *= 3600
if unit == "days":
remind *= 86400
if unit == "weeks":
remind *= 604800
Note: Another point worth raising is that
unit
could never match more than one of those if-statements, you are better of using if-elif-statements. More information about if-statements can be found here
关于python - 所有输入提醒程序的时间都以秒计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32957916/
我有一些代码: public class class1 { public class1(int count) { // count must be 4,6,8
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭
如何仅使用 css(样式)为我的 react-native View 组件背景创建此设计? 我希望 View 2 具有绿色背景,顶部有一条小曲线,与右上角的中心相交。 仅使用 borderRadius
这个问题在这里已经有了答案: How do you keep parents of floated elements from collapsing? [duplicate] (15 个答案) 关
我是一名优秀的程序员,十分优秀!