鱼C论坛

 找回密码
 立即注册
123
返回列表 发新帖
楼主: 冰河星云

小白Python练习册(10)【鱼币福利】

[复制链接]
发表于 2020-5-26 21:32:23 | 显示全部楼层
arrlist=[]
year=str(input(":"))
zidian={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31}
for a in year:
    arrlist.append(a)
yuefeng=arrlist[4]+arrlist[5]
rizi=arrlist[6]+arrlist[7]
x1=int(yuefeng)
x2=int(rizi)
x1=x1-1
yue=0
for i in range(x1):
    yue=zidian[i+1]+yue
sum=yue+x2
print("你输入的是%d月%d日" %(x1+1,x2))
print(sum)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-5-27 10:13:45 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-12-7 09:14:12 | 显示全部楼层
谢谢楼主
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-12-10 09:19:55 | 显示全部楼层
看答案                     
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-15 19:49:36 | 显示全部楼层
date=input('Enter the datetime:(20151215)')
year=int(date[:4])
month=int(date[4:6])
day=int(date[6:])
m=['0','31','28','31','30','31','30','31','31','30','31','30','31']
while month>0:
    day+=int(m[(month-1)])
    month-=1
if year/4==year//4:
    print(day+1)
else:
    print(day)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-8-22 18:47:38 | 显示全部楼层
q
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-9-27 14:54:41 | 显示全部楼层

还缺少检查输入日期是否合法的代码

本帖最后由 qq575633247 于 2023-9-27 14:58 编辑

还缺少检查输入日期是否合法的代码
  1. #include <iostream>
  2. using namespace std;

  3. class Time {
  4.         private:
  5.                 int time;
  6.                 int year;
  7.                 int mon;
  8.                 int day;
  9.                 int mon_list[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  10.         public:

  11.                 Time(int t) {
  12.                         time = t;
  13.                         year = t / 10000;
  14.                         mon = (t % 10000) / 100;
  15.                         day = t % 100;
  16.                         if (leap(year)) {
  17.                                 mon_list[1] = 29;
  18.                                 cout << year << "年是闰年,2月为" << mon_list[1] << "天。"<< endl;
  19.                         }else{
  20.                                 cout << year << "年是平年,2月为" << mon_list[1] << "天。"<< endl;
  21.                         }
  22.                 }


  23.                 bool leap(int y) {
  24.                         if (y % 400 == 0) {
  25.                                 return true;
  26.                         } else if (y % 100 != 0 && y % 4 == 0) {
  27.                                 return  true;
  28.                         } else {
  29.                                 return  false;
  30.                         }
  31.                 }

  32.                 int get_year() {
  33.                         return year;
  34.                 }

  35.                 int get_mon() {
  36.                         return mon;
  37.                 }

  38.                 int get_day() {
  39.                         return day;
  40.                 }

  41.                 int get_num() {
  42.                         int sum = 0;
  43.                         for (int i = 0; i < mon - 1; i++) {
  44.                                 sum += mon_list[i];
  45.                         }
  46.                         sum += day;
  47.                         return sum;
  48.                 }
  49.        
  50.                 void print_time() {

  51.                         cout << year << "年" << mon << "月" << day << "日";
  52.                         cout << "是" << year << "年" << "第" << get_num() << "天";
  53.                 }
  54. };


  55. int main() {
  56.         int t;
  57.         cin >> t;
  58.         Time time = Time(t);
  59.         time.print_time();
  60.         return 0;
  61. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-9-27 14:57:06 | 显示全部楼层

还缺少检查输入日期是否合法的代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-10-1 16:11:52 | 显示全部楼层
Twilight6 发表于 2020-4-30 14:56
之前很少用time,今天下午看了两小时小甲鱼整理的time文档

time?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-19 03:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表