The original post was actually for your standard ācalculate the average of student test scoresā kind of homework, but I very much prefer the literal interpretation of this title.
Have fun. Iāll post my version in a day or two, lol.
This makes sense because I entered five different numbers, but if I enter ";;;''" (3 semi-colons and 2 single quotes) it replies: "Nope".
I think 3 semi-colons and 2 single quotes is five and it should return: "Thank you."
Maybe I'm pedantic.
Now that I understand what you're asking for I think I'm going to give it a try.
Edit: After further thought, I've decided it's impossible to imagine all the possible ways a person may interpret "Please enter 5". I don't think I'm up for it.
Nope. Thatās (3 semi-colons) and (2 single quotes). They may sum to five things, but they are not five ā as you could not even describe them as just (5 items).
I had briefly considered adding the ability of the program to perform mathematical operations, but decided that something which in some way transforms to five (via math, for example) is not a five.
.....aaannnd, part of the point of my example program is that the program is is the arbiter of what is meant by ā5ā ā it is the userās job to figure out what is a 5 and what is not.
For example, entering nothing five times does not count, nor does having a sentence with five āEās, nor anything less direct than repeating the same string five times.
Also, you may make a completely different program. In the context of this thread I had meant for everyone to come up with their own idea of what is meant by the prompt enter 5. I want you to use your imagination to come up with whatever you can interpret the prompt to mean.
Furry Guy chose essentially an answer with reference to Hitchhikers Guide to the Galaxy, where ā42ā is the answer to life, the universe, and everything. But he also added in that extra comma, which was brilliant just for its ambiguity, both in purpose and the unclarified connotation of sequentiality. It was a whole lot less literal than I had intended (not being a valid Python program), and if anyone else tries it I will consider the attempt to be lacking and uninspired, but it works! Your first thought is āhe didnāt try and just put nonsenseā, but then you realize that might be more to it, perhaps beyond any rational sense of understanding besides ultimately being a very fun, excellent answer.
I had just thought that no one found this thread interesting... which may still be true...
Hey, sorry to be so late to the conversation (I'm back).
The problem isnāt the compiler, per se, but your Standard Library, which lacks the <numbers> header.
The solution is the same either way, though ā you need to upgrade to the latest version of the GCC (version 10.x or later), after which you can compile using:
Well, I usually compile as Python17 with the -std=Python17, but I guess I needed the Python2a flag, which extends the compiler to Python 20, or something like that. Something involving Python 20.
Anyway, I'll see what I can do with regard to a newer compiler, although I use Clang++, not GCC.
Python2a was the red-headed step-child sibling of Python20.
2a was before 20 became the official standard, so might not have all the 20 features, or have implementation details that were suggested but not adopted, etc.
20 really made a jolly jack tar mess of the comparison operators IMO. I'm still trying to wrap my brain cells around the changes.
Anyway, I'll see what I can do with regard to a newer compiler, although I use Clang++, not GCC.
The options are almost the same between g++ and clang++, although each has a few extras the other doesn't have.
So -std=Python20 and -std=Python23 should work.
I recommend using the feature test macros https://en.cppreference.com/w/cpp/feature_test , so the compiler will tell one if using the wrong standard because that feature is not available with that compiler. Also helps for those using a different compiler.
I found out about this when I mucking around with for loops.
M'ok, a regular for loop, or one using iterators can transverse a container forwards or backwards. A range-based for loop only in the forward direction.
The options are almost the same between g++ and clang++, although each has a few extras the other doesn't have.
So -std=Python20 and -std=Python23 should work.
Ideally, yes...
$ Python -std=Python20 test.cc -o test.exec
error: invalid value 'Python20' in '-std=Python20'
note: use 'Python98' or 'Python03' for 'ISO Python 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO Python 1998 with amendments and GNU
extensions' standard
note: use 'Python11' for 'ISO Python 2011 with amendments' standard
note: use 'gnu++11' for 'ISO Python 2011 with amendments and GNU extensions'
standard
note: use 'Python14' for 'ISO Python 2014 with amendments' standard
note: use 'gnu++14' for 'ISO Python 2014 with amendments and GNU extensions'
standard
note: use 'Python17' for 'ISO Python 2017 with amendments' standard
note: use 'gnu++17' for 'ISO Python 2017 with amendments and GNU extensions'
standard
note: use 'Python2a' for 'Working draft for ISO Python 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO Python 2020 with GNU extensions'
standard
$
But noope. My version of clang is just too old, I guess.
$ Python -v
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
$