import streamlit as st # Custom CSS to increase font size for input and output st.markdown( """ """, unsafe_allow_html=True ) # Use text input instead of slider x = st.text_input('Enter a value, and I\'ll guess your age!', '') def estimate_age_from_input(x): try: # Convert to float and get absolute value x = abs(float(x)) # Base probability of different age groups (skewed young due to internet usage) # Roughly based on internet usage demographics age_brackets = { (13, 17): 0.15, # Teens (18, 24): 0.25, # Young adults (25, 34): 0.30, # Early career (35, 44): 0.15, # Mid career (45, 54): 0.08, # Late career (55, 64): 0.05, # Pre-retirement (65, 100): 0.02 # Retirement } # Adjust probabilities based on input value if x > 1000000 or x < -1000000: # Very large/small numbers - likely young person testing limits return 18 elif x > 10000 or x < -10000: # Large numbers - probably young return 22 elif x == 69 or x == 420 or x == 80085: # Meme numbers - likely teen/young adult return 16 elif x == 0: # Default/lazy input - use median young adult age return 25 elif x == 1: # Simple input - slight skew older return 28 elif 1 <= x <= 100: # Reasonable number - use weighted distribution if x <= 20: return 24 # Young skew for small numbers else: return min(int(x * 0.8 + 15), 75) # Scale up but cap at 75 else: # Other numbers - use base distribution import random brackets = list(age_brackets.items()) weights = [p for _, p in brackets] chosen = random.choices(brackets, weights=weights)[0][0] return random.randint(chosen[0], chosen[1]) except (ValueError, TypeError): # Non-numeric input - assume young user testing system return 19 # Display the age estimation result if x: y = estimate_age_from_input(x) st.write(f'I think you\'re about {y} years old.')