Pi practice by google
Hey, I am trying to do this practice of writeing number Pi which google adds every year for 2-3 days when is Pi Day. I have no idea how to read in real time every thing that user write (and I want to do this this way that user dont have to click enter).
66 Replies
❯ Method: System.Console.ReadKey()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.
❯ Method: System.Console.ReadKey(Boolean)
Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.
React with ❌ to remove this embed.
that second overload might be useful here
or may not, depends if you want to print it or not. regardless, you can just do
Console.ReadKey
in a loop
and you will read the users input one character at a timehow can I check by if statement which key did user clicked?
I mean if this good what should I put after "!="
Also, I just really have to ask.... Why this title for the post? Why not "reading console input without enter?" or something similar
The fact thats its pi, or for a google thing is... not relevant?
bc I will for 85% ask for smth more and I thought that maybe someone will want to do same thing
can u explain what this if statement checks?
isn't that obvious from the name of the function?
the whole idea here is that the program keeps reading input one key press at a time, forever.
you cant have a forever-loop without a break thou, so I made it so if you press a non-number char it quits
since
a
isnt a valid digit of pi, for any digit position :pyeah but I want to build program that checks every number like it says write now 15 number after decimal and user writes 3.14159263 and 8th number is wrong so It stops and write NO! its wrong (it should be 3.14159265)
okay... so do that then
you can change the break condition.
something like
press Q to stop the program at any point
seems niceem idk how it helps in problem that Ive just wrote
I want to check exacly what number user clicked
and thats exactly what that code does?
bassicly yes
no, you don't understand
var key = Console.ReadKey().KeyChar;
this will read one keypressyes
but we run it in a loop, so it will trigger for every single keypress
yes
you can then look at the value of
key
and see what was pressedso I can write just ?
yep
ow
I thought it will be more complicated
why I didnt thought abt it
u already did it?
yes
it was trivial
ik but stil 💀
no
I had a much longer pi at first :p
i dont read it
okay.
thanks for deleting
and for help
welcome is you
here is a thousand digits of pi, in case ya need it
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
thanks
I have next question XD
is here a command that - u give a variable for example int i = 3 and it write every from string until the character that is on 3rd position in table?
there was such a command in python but i dont remeber its name
sure, substring, or string slicing
pi[..3]
would get all the digits until the third positiongood?
hm, given only a single digit I think substring starts at that position
❯ Method: System.String.Substring(Int32)
Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string.
❯ Method: System.String.Substring(Int32, Int32)
Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
React with ❌ to remove this embed.
yep, thats the startindex
em okay so which command should I use?
^
just write it in consolewriteline?
yes?
okay and If I want to use i variable I just replace 3 with i yes?
yes
when in doubt, $tias
should I delete those dodts?
dots**
no...
because then you'd be doing
pi[3]
and you know what that does, no?let me translate u this
you dont need to
okay
why are you using .NET Framework
what should I use?
.NET
ow
$newproject
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework.
.NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended.
https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
tbh i clicked framework bc guy in the tutorial picked it
and this is why we dont follow old tutorials
4 years are old right?
in programming, yes
but even then, making a .NET framework tutorial in 2019 kinda... sucks
.NET core came out in 2016-2017-ish?
idk
How can I do the pi[..3] command but it wont write everything in one second but it will write every number in like 1s or 0.7s?
can I use a 1 year tutorial?
probably. I mean, just check what .NET version they are using
if its 5, 6 or 7, you're fine
you cant with a single command, you'll need to make your own method with a loop and Task.Delay
wont be super simple.
good
If everything is simple then it means u are not growing
I think u know what I want to say
So I will now end the program in this version the expand it with delays
okay so smth is not right in this code and tbh idk what I did wrong so can I ask u for check it?
brb
please?
I THINK I DID IT
wait a sec
yes I did it, mr Pobiega thank u for your time and help, I can go to sleep now in peace
Hey now I am making this code better and I thought that maybe I can use tuples like in python?
in python tuples are 10 times faster than normal list/table idk how to name it in english
it was easier than I thought