Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from datetime import date | |
| import random | |
| # Vocabulary Data (Sample only) | |
| vocabulary = { | |
| "Greetings": { | |
| "Hello": "Hei", | |
| "Good morning": "God morgen", | |
| "Good night": "God natt", | |
| "Goodbye": "Ha det", | |
| "Thank you": "Takk" | |
| }, | |
| "Numbers": { | |
| "One": "En", | |
| "Two": "To", | |
| "Three": "Tre", | |
| "Four": "Fire", | |
| "Five": "Fem" | |
| }, | |
| "Colors": { | |
| "Red": "Rød", | |
| "Blue": "Blå", | |
| "Green": "Grønn", | |
| "Yellow": "Gul", | |
| "Black": "Svart" | |
| }, | |
| "Food": { | |
| "Bread": "Brød", | |
| "Milk": "Melk", | |
| "Apple": "Eple", | |
| "Water": "Vann", | |
| "Cheese": "Ost" | |
| } | |
| } | |
| daily_phrases = [ | |
| ("How are you?", "Hvordan har du det?"), | |
| ("My name is...", "Jeg heter..."), | |
| ("I am learning Norwegian", "Jeg lærer norsk"), | |
| ("What time is it?", "Hva er klokka?"), | |
| ("I like Norway", "Jeg liker Norge") | |
| ] | |
| st.set_page_config(page_title="Learn Norwegian", page_icon="🇳🇴", layout="centered") | |
| st.title("Learn Norwegian 🇳🇴") | |
| st.markdown("Welcome! This app helps you learn basic Norwegian vocabulary and phrases interactively.") | |
| # Sidebar Menu | |
| menu = st.sidebar.radio("Choose a section:", ["Vocabulary", "Flashcards", "Quiz", "Daily Phrase"]) | |
| # Vocabulary Section | |
| if menu == "Vocabulary": | |
| st.header("📖 Vocabulary") | |
| category = st.selectbox("Choose a category:", list(vocabulary.keys())) | |
| st.subheader(f"{category} Words") | |
| for eng, nor in vocabulary[category].items(): | |
| st.write(f"🔹 {eng} → {nor}") | |
| # Flashcards | |
| elif menu == "Flashcards": | |
| st.header("📝 Flashcards") | |
| cat = st.selectbox("Select a category:", list(vocabulary.keys())) | |
| words = list(vocabulary[cat].items()) | |
| word = random.choice(words) | |
| show = st.button("Show Answer") | |
| st.write(f"What is the Norwegian word for: ") | |
| st.subheader(f"🟦 {word[0]}") | |
| if show: | |
| st.success(f"✅ {word[1]}") | |
| # Quiz Section | |
| elif menu == "Quiz": | |
| st.header("🎯 Vocabulary Quiz") | |
| cat = st.selectbox("Choose a category:", list(vocabulary.keys())) | |
| question_word, correct_answer = random.choice(list(vocabulary[cat].items())) | |
| options = random.sample(list(vocabulary[cat].values()), k=3) | |
| if correct_answer not in options: | |
| options[random.randint(0, 2)] = correct_answer | |
| st.write(f"What is the Norwegian word for: {question_word}?") | |
| choice = st.radio("Options:", options) | |
| if st.button("Submit Answer"): | |
| if choice == correct_answer: | |
| st.success("Correct! 🎉") | |
| else: | |
| st.error(f"Wrong! The correct answer is {correct_answer}.") | |
| # Daily Phrase | |
| elif menu == "Daily Phrase": | |
| st.header("🔹 Daily Norwegian Phrase") | |
| phrase = random.choice(daily_phrases) | |
| st.info(f"💬 {phrase[0]} → 🇳🇴 {phrase[1]}") | |