Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
check this converting week number (int) into week day name (string) [s...
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
## thats a lame way to do it ## forget doing this, check below how its done # #def dayNameFromWeekday(weekday): # if weekday == 0: # return "Monday" # if weekday == 1: # return "Tuesday" # if weekday == 2: # return "Wednesday" # if weekday == 3: # return "Thursday" # if weekday == 4: # return "Friday" # if weekday == 5: # return "Saturday" # if weekday == 6: # return "Sunday" # else: # print('error') ## make array of all the days in order ## zeroth element is monday, sixth element is sunday days=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] ## accepts an integer, no strings, if weekday is more than 6 - prints error and returns something else than a week day def dayNameFromWeekday(weekday): if weekday>6: print('error'); return 'an unknown day' return days[weekday] ## get keyboard input but convert it to int nb = int(input('Enter weekday number [0 - 6]: ')) print('\n') ## print the result of the function print('today is: ' + dayNameFromWeekday(nb))
3
[
-
]
Show input
Absolute running time: 0.24 sec, cpu time: 0.23 sec, memory peak: 6 Mb, absolute service time: 0,25 sec
edit mode
|
history
|
discussion
Enter weekday number [0 - 6]: today is: Thursday