Why do I keep getting recommended these short scripting tutorials using "clever" mathematics and painfully outdated syntax? As long as we're using bash, zsh, or ksh... ~~~~~~~~~~ while (( num > 0 )); do (( rem = num % 10 )) (( rev = rev * 10 + rem )) (( num = num / 10 )) done if (( rev == n )); then .... ~~~~~~~~~~ 1. [..] is an ancient relic. For arithmetic expressions and tests, use ((..)) instead. It supports actual operators like > (greater than). 2. For string and file tests, use [[..]] instead. It is more versatile and robust. The only time you'll ever need the old [..] test is for posix-level portability. 3. `..` is _extremely_ outdated. Even posix has supported the more robust $(..) form of command substitution for decades. 4. expr is an unnecessary call to an external command. bash can do integer arithmetic internally within ((..)) or $((..)). zsh, ksh also support floating point. 5. A challenge like this can be made more general and flexible as a simple string check. ~~~~~~~~~~ read -r string1 for (( n=1; n<=${#text}; n++ )); do #c-style for loop to reverse the string, character by character. string2+=${string1: -n:1} #returns the nth character from the end of the string. watch the space in front of the -n. done if [[ $string1 == $string2 ]]; then echo "It's a palindrome" else echo "It's not a palindrome" fi #Here's another variation for the loop, running it in the opposite direction: for (( n=${#text}-1; n>=0; n-- )); do text2+=${text1:n:1} done ~~~~~~~~~~ 6. Check out Greg's Wiki, particularly the BashFAQ and BashPItfalls pages, for details. Pay special attention to FAQs #31 and #82, and the ArithmeticExpression page.
@davidh.49443 ай бұрын
Don't use [...] for arithmetic evaluation, use ((..)). Inside them you can use actual math operators, including ((x?y:z)) ternary operations, set variables with =, and use them without $. In fact, don't use [...] at all. All of the advanced shells support the more powerful and flexible [[...]]. And `..` backticks, too? <sigh>. $(..) is the recommended pattern for subshell expansion. expr is also unnecessary, it being just another (and outdated) way to invoke an arithmetic context: Try ((i++)) instead. But a for loop would eliminate it entirely. See BashFAQ #32 and #82, and the page on ArithmeticExpression at Greg's Wiki for details. ~~~~~ declare -i large=$1 min=$1 num # the 'in $@' isn't actually necessary; for loops iterate over input arguments by default, but it can be clearer to read. for num in "$@"; do (( large = num > large ? num : large )) (( min = num < min ? num : min )) done printf 'Largest number is: %d Smallest number is: %d ' "$large" "$min" ~~~~~ In any case, as long as we are talking positive integer values only, we don't need math operations at all. We can use bash's sparse arrays and expansion operators instead. ~~~~~ for n; do nums[n]=$n # set $n as both the index and content of the array elements done # -1 prints the last (highest) array entry, ":0:1" means print one entry, starting from index 0. printf 'Largest number is: %d Smallest number is: %d ' "${nums[-1]}" "${nums[@]:0:1}" ~~~~~ Note1: bash's arithmetic support is integer only. You have to turn to external tools like awk or bc for decimal support. Note2: zsh does have floating point support, but it doesn't have sparse arrays. It does have built-in sorting algorithms, however, so it should be possible to work out something similar.
@konscomputertutorials74732 ай бұрын
Thanks for the correction. I kindly appreciate
@rahatadnaan5 ай бұрын
thanks
@okolifranklin21115 ай бұрын
Great video! After installing mine, the anaconda navigator do not open?What could be the problem
@konscomputertutorials74735 ай бұрын
Type jupyter in the start memu. You should see it there
@AjitA-pi8pp6 ай бұрын
tq very useful
@konscomputertutorials74736 ай бұрын
Am glad it could help. Make sure to share so more people can benefit from it too.
@wamo47766 ай бұрын
Thank you sir📚
@Matrix-rq1kh7 ай бұрын
nice video but i have one question, in may be previous versions and many other tutorials i saw when we click on 'new' there is option of creating python 3 file while in this newer version its not there we have to create a notebook and then select kernal. Do you know y is it so
@konscomputertutorials74737 ай бұрын
This is the latest version released in February 2024. On the file downloaded you will see the date there
@Viewpoint3147 ай бұрын
Is there a good Jupyter tutorial somewhere? This video was excellent.
@konscomputertutorials74737 ай бұрын
I will be uploading a video on how to use jupyter shortly. Just stay tuned
@Viewpoint3147 ай бұрын
How can I install Keras and other packages?
@Viewpoint3147 ай бұрын
This all worked.
@konscomputertutorials74737 ай бұрын
Am glad it helped.
@Viewpoint3147 ай бұрын
If I have a saved Python program then how can I load it into Jupyter and run it instead of typing my Python code line by line?
@konscomputertutorials74737 ай бұрын
to run it all as one you just need to include all the code in one cell
@konscomputertutorials74737 ай бұрын
jupyter is great when you want to divide and run your code snippets separately but if you want your file to run all as one . then it will be better to use other editors such as pycharm , vscode etc which are known for running the complete file at once.
@hiwotworkiye98819 ай бұрын
why is mine not working??
@konscomputertutorials74739 ай бұрын
please make sure to follow the steps carefully . download the correct file for your system and follow the instructions. this steps will work for windows 8/10/11. if your are using windows 7 then install python 2
@SJ78_Harsh Жыл бұрын
right or wrong ? echo "Enter numbers separated by spaces:" read -a numbers max=${numbers[0]} min=${numbers[0]} for num in "${numbers[@]}"; do if [ "$num" -gt "$max" ]; then max="$num" fi if [ "$num" -lt "$min" ]; then min="$num" fi done echo "Maximum: $max" echo "Minimum: $min"
@jaketyler07 Жыл бұрын
tqsm brother... i was given a topic to speak on computer application in business and uve just gave me an idea of what I should speak exactly...
@konscomputertutorials7473 Жыл бұрын
Am glad it helped 😊
@tendaishenembaware6499 Жыл бұрын
I’m having an error that says I can’t use done!
@konscomputertutorials7473 Жыл бұрын
Check your syntax make sure the while loop is written correctly While command do // Statement // done Follow the above structure and make sure it's correct
@soulblue5593 Жыл бұрын
Thanks a lot sir
@srishtishrivastava8818 Жыл бұрын
Nice video... Topic explaination is very simple and to the point.
@konscomputertutorials7473 Жыл бұрын
Thank you
@gaminguniverse7741 Жыл бұрын
nice work
@easyak27872 жыл бұрын
value of time great lecture sir g
@konscomputertutorials74732 жыл бұрын
thanks
@konscomputertutorials74732 жыл бұрын
Kons tutorial is here for you . hope you do understand the tutorials . please make sure to like and subscribe . and also if you can write your opinions here in the comment section