This guide will walk you through the steps to push a local project to a remote Git repository.
Step 1: Navigate to Your Project Directory
Open a terminal and navigate to your project directory using the cd
command:
cd path/to/your/project
Step 2: Initialize a Git Repository
Initialize a new Git repository in your project directory:
git init
Step 3: Add Your Files
Add all the files in your project to the Git repository:
git add .
Step 4: Commit Your Changes
Commit the changes with a message:
git commit -m "Your commit message"
Step 5: Link Your Local Repository to the Remote Repository
Link your local repository to the remote repository:
git remote add origin your-repository-url
Replace your-repository-url with the URL of your remote repository.
Step 6: Push Your Local Repository to the Remote Repository
Finally, push your local repository to the remote repository:
git push -u origin master
If you're asked for a username and password, enter your GitHub username and password.
Congratulations! You've now pushed your project to a remote Git repository.
User Information Input and Storage 🐍
This Python project prompts the user for their name, age, and hobbies, and stores this information in a JSON file.
import json
def get_input(prompt, validation_func):
while True:
data = input(prompt)
if validation_func(data):
return data
else:
print("Invalid input. Please try again.")
def get_hobbies():
hobbies = []
while True:
hobby = input("Enter a hobby (type 'done' when finished): ")
if hobby.lower() == 'done':
break
elif hobby: # check if hobby is not an empty string
hobbies.append(hobby)
else:
print("Invalid input. Please try again.")
return hobbies
def save_user_info(name, age, hobbies):
user_info = {
"name": name,
"age": age,
"hobbies": hobbies
}
try:
with open("user_info.json", "w") as file:
json.dump(user_info, file)
except IOError:
print("Error writing to file. Please check if the file is open in another program.")
def main():
name = get_input("Enter your name: ", lambda x: x)
age = get_input("Enter your age: ", lambda x: x.isdigit() and int(x) > 0)
print("Enter your hobbies (type 'done' when finished):")
hobbies = get_hobbies()
save_user_info(name, age, hobbies)
print("\nName:", name)
print("Age:", age)
print("Hobbies:", ", ".join(hobbies))
if __name__ == "__main__":
main()
{"name": "Niladri", "age": "23", "hobbies": ["Cooking", "Football", "Cricket"]}
How to Run
- Ensure you have Python installed on your machine.
- Clone this repository or download the
main.py
file. - Open a terminal and navigate to the directory containing
main.py
. - Run the command
python main.py
.
How it Works
When you run main.py
, the program will prompt you for your name, age, and hobbies.
For the hobbies, you can enter as many as you like. After each hobby, press enter to input another one. When you're done entering hobbies, type 'done' and press enter.
The program will then store your information in a JSON file named user_info.json
in the same directory.
Future Runs
On subsequent runs, the program will first display the information entered during the previous run. If it's the first time you're running the program or if the user_info.json
file doesn't exist, it will print "No previous user information found."
Project Level
This project is suitable for both high school and introductory university level courses in programming or computer science. It's a good project for learning and practicing Python basics.
Top comments (0)