h=int(input("Enter Hours: ")) m=int(input("Enter Minutes: ")) s=int(input("Enter Second: ")) if((h<0)or(m<0)or(s<0)): # hour or minute or seconds can not be -ve number print("invalid data \n"); elif((h>12)or(m>59)or(s>59)): # the extreme boundary condition print("\n invalid time entry \n"); else: s += 1 # increase the seconds by one if(s>59): s=0; # after increment when s becomes more than 59 minute changes by 1 m += 1 if(m>59): m=0 h += 1 if(h>12): h=1; print("Time updated by one second is \n",h, m, s); Output 1: Enter Hours: 12 Enter Minutes: 59 Enter Second: 59 Time updated by one second is 1 0 0 Output 2: Enter Hours: -2 Enter Minutes: 4 Enter Second: 8 invalid data Output 3: Enter Hours: 2 Enter Minutes: 59 Enter Second: 65 invalid time entry
इन्हें भी देखें।
- while loop
- for loop
- nested loops
- loop control statements (Break, Continue, Pass)
- if statement
- if-else statement
- if-elif statement
- nested if statement
- range() function
- keywords
- Identifiers (names)
- Literals
- Operators
- punctuatorts
Python Programs के लिये यहाँ click करें।