Python input()使用实例

1. input() 输入多个数字

while True:
    user_choice=input("请输入(help:帮助):")
    if user_choice=="SAT":
        t_hour,t_min,t_sec=eval(input("请输入(以,分隔):"))
        print("输入的结果是:",t_hour,t_min,t_sec)
    
    elif user_choice=="q" or user_choice=="Q":        #如果输入q、Q 
        break

2.定时每天自动执行线程任务

#!/usr/bin/python
from threading import Timer
import time
import threading
import sys
  
# 定义线程调用函数
class threading_TWHA(threading.Thread):
    def __init__(self, threadID, name, counter):
        threading.Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter

    def run(self):
        while True:
            time_now = time.strftime("%H:%M:%S", time.localtime()) # 刷新
            if time_now == t_now1:  
                print("Server打开")
                print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
                time.sleep(2) # 因为以秒定时,所以暂停2秒,使之不会在1秒内执行多次

            if time_now == t_now0: 
                print("Server关闭")
                print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
                time.sleep(2) # 因为以秒定时,所以暂停2秒,使之不会在1秒内执行多次

            if user_choice=="SA0" or user_choice=="sa0":  # 关闭自动开关机线程
                print("Server线程关闭")
                return
                
t_now1 = "17:22:00" # 自动开机时间初始化
t_now0 = "17:22:10" # 自动关机时间初始化

while True:
    user_choice=input("请输入(help:帮助):")
    if user_choice=="SA1" or user_choice=="sa1":    # 开始自动开关机线程
        thread3 = threading_TWHA(3,"heWaterHeaterAuto",3)
        thread3.start()         
        print("Server线程打开")

    if user_choice=="SAT1" or user_choice=="sat1":  # 开机时间设置
        t_now1=input("Server自动开机时间修改(例如:15:30:00):")
        print("输入结果是:",t_now1)

    if user_choice=="SAT0" or user_choice=="sat0":  # 关机时间设置
        t_now0=input("Server自动开机时间修改(例如:15:30:00):")
        print("输入结果是:",t_now0)

    if user_choice=="q" or user_choice=="Q":        #如果输入q、Q 
        user_choice="sa0"   # 先退出线程
        break
        

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sam-zy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值