Ask coding questions

← Back to all posts
How do I make it so that if I enter my_secret key it'll say "Logged in!"
MatthewADev (18)

Whoever helps me with it can gets 5 cycles.

Answered by Coder100 (18882) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18882)

Step 1:
read about the environment variables so you know where to set the key:
https://docs.replit.com/repls/secrets-environment-variables

Step 2:
Assuming you set the key as my_secret, you just need to do:

import os
my_secret = os.getenv('my_secret')
k = input('KEY :')
if k == my_secret:
  print("logged in!")
  # more code...
IMayBeMe (535)

Just do:

if k == my_secret:
  print('Logged in!')
OldWizard209 (1614)

firstly, there is no need to say "Whoever helps me with it can gets 5 cycles.

". Anyways, use an if statement to implement this:

import os
my_secret = os.environ['key']
k = input('KEY: ')

if k == my_secret:
  print('Logged in!')